本文整理汇总了Java中android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP属性的典型用法代码示例。如果您正苦于以下问题:Java Intent.FLAG_ACTIVITY_CLEAR_TOP属性的具体用法?Java Intent.FLAG_ACTIVITY_CLEAR_TOP怎么用?Java Intent.FLAG_ACTIVITY_CLEAR_TOP使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.content.Intent
的用法示例。
在下文中一共展示了Intent.FLAG_ACTIVITY_CLEAR_TOP属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleActivityStack
public static void handleActivityStack(ActivityInfo info, Intent intent) {
// Handle launchMode with singleTop, and flag with FLAG_ACTIVITY_SINGLE_TOP
int launchMode = info.launchMode;
int flag = intent.getFlags();
String launchActivityName = info.name;
String prevActivityName = null;
List<WeakReference<Activity>> activityList = ActivityTaskMgr.getInstance().getActivityList();
if (activityList.size() > 0) {
Activity lastActivity = activityList.get(activityList.size() - 1).get();
prevActivityName = lastActivity.getClass().getName();
}
if (StringUtils.equals(prevActivityName, launchActivityName)
&& (launchMode == ActivityInfo.LAUNCH_SINGLE_TOP || (flag & Intent.FLAG_ACTIVITY_SINGLE_TOP) == Intent.FLAG_ACTIVITY_SINGLE_TOP)) {
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
} else if (launchMode == ActivityInfo.LAUNCH_SINGLE_TASK || launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE
|| (flag & Intent.FLAG_ACTIVITY_CLEAR_TOP) == Intent.FLAG_ACTIVITY_CLEAR_TOP) {
int i;
boolean isExist = false;
for (i = 0; i < activityList.size(); i++) {
WeakReference<Activity> ref = activityList.get(i);
if (ref!=null && ref.get()!=null && ref.get().getClass().getName().equals(launchActivityName)) {
isExist = true;
break;
}
}
if (isExist) {
for (WeakReference<Activity> act : activityList.subList(i + 1, activityList.size())) {
if(act!=null && act.get()!=null) {
act.get().finish();
}
}
activityList.subList(i + 1, activityList.size()).clear();
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
}
}
}
示例2: onNewIntent
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if ((Intent.FLAG_ACTIVITY_CLEAR_TOP & intent.getFlags()) != 0 ){
finish();
}
}