java [Android Intent Filter]标签:Android

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java [Android Intent Filter]标签:Android相关的知识,希望对你有一定的参考价值。

//http://stackoverflow.com/questions/3473168/clear-the-entire-history-stack-and-start-a-new-activity-on-android
In API level 11 a new Intent Flag was added just for this: Intent.FLAG_ACTIVITY_CLEAR_TASK
Just to clarify, use this:
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
Unfortunately for API lvl <= 10, I haven't yet found a clean solution to this. As per @Ben Pearson's comment, for API <=10 now one can use IntentCompat class for the same. One can use IntentCompat.FLAG_ACTIVITY_CLEAR_TASK flag to clear task. So you can support pre API level 11 as well.
  
  
Intent newIntent = new Intent(D.this,B.class);
newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(newIntent);

The new IntentCompat should've helped on that, but apparently the flag is ignored for API lower than 11.
  
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
IntentCompat.FLAG_ACTIVITY_CLEAR_TASK);

以上是关于java [Android Intent Filter]标签:Android的主要内容,如果未能解决你的问题,请参考以下文章

java [Intent] Intent片段以启动Activity,Service或发送广播。 #android_snippet #android

java [Android Intent Filter]标签:Android

java [Intent Extras to String]转换Intent的Extras为可读的String #Android

如何在Android中启动JAVA程序

Android 8.0:java.lang.IllegalStateException:不允许启动服务 Intent

试图用 Intent 在 Android Studio 中解释一个 Java 方法