If my procedure is following:
- Launch Activity A -> Activity B
- Press 'Home' button.
- Click on the application again.
Result: 'Activity B' shows up (it resumes).
- Launch Activity A -> Activity B
- Press 'Back' button.
- Click on the application again.
Result: 'Activity A' shows up (it restarts).
I want to do exactly same from the BroadcastReceiver.
- Launch Activity A -> Activity B
- Press 'Home' button.
- BroadcastReceiver receives a broadcast and want to "resume" application.
My expected result: 'Activity B' shows up.
I want to do exactly same from the BroadcastReceiver.
- Launch Activity A -> Activity B
- Press 'Back' button.
- BroadcastReceiver receives a broadcast and want to "restart" application.
Current result: 'Activity A' shows up.
Following code doesn't do what I expect:
public void onReceive(Context context, Intent intent) {
Intent i = new Intent(context, ActivityA.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
I also tried "Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY" but no luck.
My gosh, I made it working!!
Thank you for other answers you guys provided, but they weren't what I was looking for.
This will do the job:
check out this
set flags to your intent
Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
andIntent.FLAG_ACTIVITY_NEW_TASK
as following