Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FLAG_ACTIVITY_CLEAR_TOP calls onCreate() instead of onResume()

Tags:

android

So I have an abstract class extended through the entire app that overrides the back key to reorder Activity A to the front (With the flag).

So, it would be:

A > B > anywhere, and the back key should bring me back to A

I'm using the FLAG_ACTIVITY_CLEAR_TOP, but it is entirely refreshing A for some reason and I don't want that.

So: Flag_activity_clear_top is reloading the onCreate() rather than onResume(). What gives?

like image 696
VicVu Avatar asked Sep 24 '12 20:09

VicVu


2 Answers

If you want the activity to just be brought to the top without restarting it set the launchMode of the activity to singleTop in the manifest. You will receive a call to onNewIntent when the activity is being brought to the top. onNewIntent is called before onResume. If you only want this behavior for the specific intent you can add the FLAG_ACTIVITY_SINGLE_TOP(in addition to FLAG_ACTIVITY_CLEAR_TOP) to the intent with the addFlags call instead of the manifest.

like image 197
Bobbake4 Avatar answered Oct 04 '22 08:10

Bobbake4


Intent intent = new Intent(CurrentActivity.this, ActivityNeedOnTop.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                    startActivity(intent);
                    CurrentActivity.this.finish();
like image 32
aanshu Avatar answered Oct 04 '22 10:10

aanshu