FLAG_ACTIVITY_SINGLE_TOP

来源:互联网 发布:淘宝退货卖家拒签 编辑:程序博客网 时间:2024/05/16 12:56

FLAG_ACTIVITY_SINGLE_TOP :如果当前栈顶的activity就是要启动的activity,则不会再启动一个新的activity

实例:

我们有一个apk,apk中包含两个Activity:MainActivity和ActivityA,点击MainActivity启动ActivityA,点击ActivityA还是启动ActivityA,但我们设置FLAG_ACTIVITY_SINGLE_TOP标记:

public void onClick(View v) {// TODO Auto-generated method stubLog.i(TAG, "--onClick--task id = " + getCurrentTaskId());Intent intent = new Intent("com.leaves.ipanel.ActivityA");  //intent.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK);intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);startActivity(intent); }    
启动动ActivityA,随便我们怎么再点击,都只有一个ActivityA实例,堆栈:

ACTIVITY MANAGER ACTIVITIES (dumpsys activity activities)  Main stack:    TaskRecord{438f1ed8 #9 A com.leaves.ipanel U 0}    Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.leaves.ipanel/.MainActivity }      Hist #2: ActivityRecord{4265b1b0 u0 com.leaves.ipanel/.ActivityA}        Intent { act=com.leaves.ipanel.ActivityA flg=0x20000000 cmp=com.leaves.ipanel/.ActivityA }        ProcessRecord{4292a550 2115:com.leaves.ipanel/u0a10061}      Hist #1: ActivityRecord{42485758 u0 com.leaves.ipanel/.MainActivity}        Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.leaves.ipanel/.MainActivity }        ProcessRecord{4292a550 2115:com.leaves.ipanel/u0a10061}    TaskRecord{426f4820 #2 A com.android.launcher U 0}    Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10600000 cmp=com.android.launcher/com.android.launcher2.Launcher }      Hist #0: ActivityRecord{4291c7b0 u0 com.android.launcher/com.android.launcher2.Launcher}        Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10000000 cmp=com.android.launcher/com.android.launcher2.Launcher }        ProcessRecord{4267f0b8 636:com.android.launcher/1000}



原创粉丝点击