How to resume previous activity instead of going t

2019-09-19 03:53发布

问题:

I have created a settings activity which will get fired when I press the two volume keys simultaneously. I am invoking this settings activity using an Intent from PhoneWindowManager.java as below,

Intent intent = new Intent("com.MyApp.Settings.EXT_SETUP");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intnt);

I am also running a custom launcher application. While the custom launcher is running, I am able to invoke my settings Activity by pressing the volume buttons.

But the problem is, after exiting the custom settings activity ( by calling finish()), the control is not going to the custom launcher (which is the previous active task). Instead Android is calling home launcher activity which is resulting in going to HOME screen instead of resuming my custom launcher.

I have tried the Intent flags FLAG_ACTIVITY_CLEAR_TOP, FLAG_ACTIVITY_PREVIOUS_IS_TOP. But nothing worked.

Please let me know on how I can invoke the custom launcher after exiting my settings Activity.

Thanks in advance, Phani

回答1:

Chk this out

Intent intent = new Intent("com.MyApp.Settings.EXT_SETUP");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
mContext.startActivity(intnt);

Intent.FLAG_ACTIVITY_SINGLE_TOP); If set, the activity will not be launched if it is already running at the top of the history stack.



回答2:

Use this :

intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);