本文整理匯總了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();
}
}