2

How can I bring my application back to foreground, same as when the user presses on the application icon/image in the recents activity.

TacB0sS
  • 10,106
  • 12
  • 75
  • 118

2 Answers2

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
  • 1
    I 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
    Cool! that was my mistake expecting something to do as it named :) – TacB0sS Sep 10 '13 at 18:06
0

Do you need to bring back your app based on some global keyevents?

Couple of things that came in my mind.. You can to write a view and listen to the global touch. Something like this thats stated in example

prijupaul
  • 2,076
  • 2
  • 15
  • 17