How can I bring my application back to foreground, same as when the user presses on the application icon/image in the recents activity.
Asked
Active
Viewed 340 times
2
-
Pressing from where ? startActivity() :/ – Rachit Mishra Sep 10 '13 at 09:23
-
1still not clear, what you want to acheive ! – Rachit Mishra Sep 10 '13 at 11:12
-
Thanks for the effort, I guess this question is too obvious, and sometime been so obvious is hard to explain, David got it though... – TacB0sS Sep 11 '13 at 08:12
2 Answers
3
You just do what Android does when the user presses the application icon/image:
Intent intent = new Intent(context, MyRootActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
Make sure that you specify the root activity of your application (ie: the one with ACTION=MAIN and CATEGORY=LAUNCHER).

David Wasser
- 93,459
- 16
- 209
- 274
-
But if I start it in a new task, why does the original task comes back to life? – TacB0sS Sep 10 '13 at 15:58
-
1I didn't name the flag ;-) If you have a problem with the name, you can complain to the Android developers. The documentation for this flag reads: **"if a task is already running for the activity you are now starting, then a new activity will not be started; instead, the current task will simply be brought to the front of the screen with the state it was last in."** This is the same behaviour as when you "launch" an application from the HOME screen, but that application is already running. Really what you want is to just bring that application to the foreground. – David Wasser Sep 10 '13 at 16:12
-
1