0

I would like to exit the app completely. I tried finish() and android.os.Process.killProcess(Process.myPid()) but they still leave app running in background.

A lot of people said that this is impossible, but my bank app is able to do that. When you exit that bank app, you can't see it in Recent Apps menu.

Does anyone know how to do it?

user3051755
  • 1,497
  • 2
  • 16
  • 27
  • Are you trying to kill the app or hide it from the recent apps menu? – Jared Burrows Mar 31 '15 at 23:20
  • 1
    Do you mean http://stackoverflow.com/questions/13704782/android-remove-application-from-recent-apps Hidden from recent apps doesn't necessarily mean the app has really been killed. – Thom Wiggers Mar 31 '15 at 23:20
  • http://www.vogella.com/tutorials/AndroidLifeCycle/article.html – Brian Var Mar 31 '15 at 23:30
  • You do not want to kill your app's process. Let Android handle memory management and your lifecycle. What you probably mean is that you would like to exclude it from the recents menu. Or, you might want WindowManager.LayoutParams.FLAG_SECURE. Look into those two. – Eric Cochran Mar 31 '15 at 23:36

2 Answers2

4

When you exit that bank app, you can't see it in Recent Apps menu.

That has nothing to do with a process. Processes and tasks are not particularly related.

Try finishAndRemoveTask() (API Level 21+), or perhaps finishAffinity() (API Level 16+), both methods on Activity. Or, as Thom Wiggers suggests in the comments, perhaps the app is not showing up in the recent-tasks list at all, via android:excludeFromRecents.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • 1
    In addition, regarding banking applications, WindowManager.LayoutParams.FLAG_SECURE is probably what is desired, rather than excludeFromRecents. – Eric Cochran Mar 31 '15 at 23:38
1

To remove activity from recents use this in the activity tag in manifest:

android:excludeFromRecents="true"

To remove application from background use below code. Please note that this will not remove the application from recents. It justs starts the application from the starting activity.

int pid = android.os.Process.myPid();
android.os.Process.killProcess(pid);

or

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent);
Aakash
  • 5,181
  • 5
  • 20
  • 37