-1

I want to create an app with this ability:when the user press back button.don't close app & stay in running list in settings->application manager->running
& stay in running list when user press home button too.

I like to make an app that there isn't in task manager->active application but there is in settings->application manager->running such as Viber,Tango,Gmail

user3257386
  • 284
  • 1
  • 2
  • 11

4 Answers4

1

Add onBackPressed() into your Activity:

@Override
    public void onBackPressed() {
     moveTaskToBack(false);
  }
M D
  • 47,665
  • 9
  • 93
  • 114
0

Override onbackpress and do the code for application to go background

Jithu
  • 1,478
  • 1
  • 13
  • 21
0

you can achieve it as follow:

@Override
public void onBackPressed() {
    moveTaskToBack(false);
}

to minimize your app use moveTaskToBack(true);

NOTE: don't write super.onBackPressed();

Gopal Gopi
  • 11,101
  • 1
  • 30
  • 43
dinesh sharma
  • 3,312
  • 1
  • 22
  • 32
  • 1
    moveTaskToBack(false); `true` will close the application or activity while OP has asked not to close the activity. – user3264399 Feb 04 '14 at 12:32
  • 1
    welcome, just to add one more thing that above code doesn't minimize the application. – user3264399 Feb 04 '14 at 12:34
  • but with this code app stay in task manager too & when the user press end my app will be close. but there are many app that there aren't in task manager but are running how can I do it? – user3257386 Feb 04 '14 at 12:51
  • this is another question. But as per my knowledge no one can make an app that is not killed by the app manager. – dinesh sharma Feb 04 '14 at 12:54
  • Even if you write a background service to wake up your app the app manager will also kill the service. – dinesh sharma Feb 04 '14 at 12:56
  • ok I know it.but I like to make an app that there isn't in task manager->active application but there is in settings->application manager->running such as Viber,Tango,Gmail – user3257386 Feb 04 '14 at 13:05
  • They show it in the running because they have background service running but the app may have closed – dinesh sharma Feb 04 '14 at 13:44
0

Why do you need to keep your app running? If you need to process data while the user is not in your app, you need a Service:

http://www.vogella.com/tutorials/AndroidServices/article.html

Android simple service not starting

Community
  • 1
  • 1
Jim
  • 10,172
  • 1
  • 27
  • 36