简体   繁体   中英

Clear backstack in Android pre Honeycomb?

Is there an easy way or another workaround to delete the backstack in Android pre Honeycomb(before API level 11)? People suggest using the FLAG_ACTIVITY_CLEAR_TOP in conjunction with FLAG_ACTIVITY_NEW_TASK when starting a new activity, but this does only delete the stack on top of my current position, not the stack under my position. It should not be that hard to start from a fresh task. Some ideas around this? I can not use FLAG_ACTIVITY_CLEAR_TASK because I need to support those versions beneath api level 11. Is there an equivalent to FLAG_ACTIVITY_CLEAR_TASK that clears the whole navigation backstack. Or something similiar to FLAG_ACTIVITY_REORDER_TO_FRONT that reorders to back, and then I can clear everything on top of it. All suggestions are highly appreciated:) Thanks!

You can also use a broadcast listener.

Just make a broadcast listener in all the activities with a "STRING" to recognise.

Whenever you want to delete all the activities, fire the intent.

Those activities that have registered for the above listener (to be done by depending on which activites you wanna finish), will intercept that and will get finish.

This is gonna work in any release of the Android.

you are looking for this:

Intent intent = new Intent(activity, activityClass);
ComponentName cn = intent.getComponent();
Intent mainIntent = IntentCompat.makeRestartActivityTask(cn);
activity.startActivity(mainIntent);

use android compatibillity lib from google - found in the sdk.

depending on your API version it might also be:

Intent mainIntent = IntentCompat.makeMainActivity(cn);

为什么不为所有先前的活动创建一个静态ArrayList并在需要使用该活动时清除不需要的那些活动。destroy()

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