简体   繁体   中英

Getting Illegal Argument Exception: addAppToken Invalid stackId while launching a activity

I am trying to open an Activity from another Activity using the flag CLEAR_TASK, but sometimes I am getting an exception.

java.lang.IllegalArgumentException: addAppToken: invalid stackId=1

It's a intermittent issue and is not happening every time.

Intent intent1 = new Intent(ActivityA.this, ActivityB.class);
intent1.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);

startActivity(intent1); 

My ActivityA is a SingleInstance and ActivityB is a SingleTask.

If set in an Intent passed to Context.startActivity() , this flag will cause any existing task that would be associated with the activity to be cleared before the activity is started. That is, the activity becomes the new root of an otherwise empty task, and any old activities are finished. This can only be used in conjunction with FLAG_ACTIVITY_NEW_TASK .

http://developer.android.com/reference/android/content/Intent.html

I found same error like you.and finally i knew why,just because i start same activity twice at same time.

but there something bothers me.

i develop a launcher app,this error only occurred when i boot or reboot my device,after i exited my app,then restart it,everything runs good,even this wrong code still there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM