如何使用IntentCompat.makeRestartActivityTask()?如何使用、IntentCompat、makeRestartActivityTask

由网友(No Name)分享简介:我想实现一个按钮,这将导致我的应用程序可以追溯到第一项活动和行动,如果它是(几乎)重新启动各地。这code 意图newIntent =新的意图(currentActivity.getApplicationContext(),StartActivity.class);newIntent.setFlags(Intent....

我想实现一个按钮,这将导致我的应用程序可以追溯到第一项活动和行动,如果它是(几乎)重新启动各地。这code

 意图newIntent =
        新的意图(currentActivity.getApplicationContext(),StartActivity.class);
newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK + Intent.FLAG_ACTIVITY_CLEAR_TASK);
currentActivity.startActivity(newIntent);
 

似乎是工作行为运行机器人4.1较新片剂,但它不是运行机器人2.3.4一个较旧的设备上工作。

我发现一对夫妇的线程这一点:

Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK不工作的Andr​​oid

清除任务中的所有活动?

阅读印刷精美,使我相信我应该使用Android的支持,v4.jar的IntentCompat类,http://developer.android.com/reference/android/support/v4/content/IntentCompat.html

不幸的是,该文件不包含任何的例子,我非常不确定我应该如何使用IntentCompat。我发现的唯一的例子是这样的:无法启动MainActivity了Android 2.3

这使我相信我应该做这样的事情:

 意图newIntent = IntentCompat.makeRestartActivityTask(CN);
 
利用intent启动浏览器

但是,这是给我一个编译器错误,说makeRestartActivityTask是一个未定义的符号。

我猜这意味着我没有正确添加Android的支持 - v4.jar我的编译环境(IntelliJ IDEA的12个社区版),但我想这样做,以多种不同的方式,它仍然没有按科技工作。

所以,我有两个问题:

难道IntentCompat我试图使用看起来是正确的?

如何让编译器停止说makeRestartActivityTask是一个未定义的符号?

解决方案

这是我如何使用IntentCompat

 意图int​​entToBeNewRoot =新的意图(这一点,MainActivity.class);
    组件名CN = intentToBeNewRoot.getComponent();

    意图mainIntent = IntentCompat.makeRestartActivityTask(CN);

    startActivity(mainIntent);
 

这有效地取代了我没有再通缉任务根与MainActivity。它工作在Gingerbeard和ICS。我还没有看到是一个未定义的符号的消息。

I'm trying to implement a button that will result in my app going back to the first activity and acting as if it was (almost) restarted all over. This code

Intent newIntent =
        new Intent(currentActivity.getApplicationContext(), StartActivity.class);
newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK + Intent.FLAG_ACTIVITY_CLEAR_TASK);
currentActivity.startActivity(newIntent);

seems to be working OK for a newer tablet that is running Android 4.1, but it doesn't work on an older device that is running Android 2.3.4.

I've found a couple of threads about this:

Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK not working Android

Clear all activities in a task?

Reading the fine print leads me to believe I should be using the IntentCompat class in android-support-v4.jar, http://developer.android.com/reference/android/support/v4/content/IntentCompat.html

Unfortunately, the documentation does not contain any examples, and I'm very unsure of how I should be using IntentCompat. The only example I've found is this: Not start MainActivity with android 2.3

which leads me to believe I should be doing something like this:

    Intent newIntent = IntentCompat.makeRestartActivityTask(cn);

But this is giving me a compiler error, saying "makeRestartActivityTask" is an undefined symbol.

I'm guessing this implies I haven't added android-support-v4.jar correctly to my build environment (IntelliJ IDEA 12 community edition), but I've tried doing that in several different ways, and it still doesn't work.

So I have two questions:

Does my attempted usage of IntentCompat look correct?

How do I get the compiler to stop saying that "makeRestartActivityTask" is an undefined symbol?

解决方案

This is how I'm using IntentCompat

    Intent intentToBeNewRoot = new Intent(this, MainActivity.class);
    ComponentName cn = intentToBeNewRoot.getComponent();

    Intent mainIntent = IntentCompat.makeRestartActivityTask(cn);

    startActivity(mainIntent);

This effectively replaces my no-longer-wanted task root with MainActivity. It works in Gingerbeard and ICS. I haven't seen the "is an undefined symbol" message.

阅读全文

相关推荐

最新文章