0

I'm trying to force close my app in order to hide what user did. I'm using the next code (that is half-working). It disappears from the screen but in when I press the button of the open apps (the button on the bottom, next to home and back buttons) I still can see it. Do you guys know what is the best way to kill the app completely?

 finish();
 moveTaskToBack(true);
 System.exit(0);

I'm gonna try to explain it better: The thing is i have an activity, when i press the specified Button it opens another one that has a timer. if the user doesn't do a combination before the timer expires i want to force close all the app. The thing is that doing what I wrote in the code, my app minimizes and when I press the button of the bottom (the one to see all my open apps) I still can see it is open, not in the second activity but in the first one.

I don't want to remove it from recent application list, is not there where it is once i try to close it.

thank you guys

Álvaro Koke
  • 113
  • 1
  • 10
  • 5
    Depending on the device, the apps in that list may not be open, but rather, recently opened. You might prevent from appearing in the list: http://stackoverflow.com/questions/3762763/how-to-remove-application-from-recent-application-list – Al Lelopath Mar 21 '16 at 19:37
  • the problem is that it closes the activity where i am but it doesn't close the main activity... – Álvaro Koke Mar 21 '16 at 19:45
  • 1
    As Pztar points out, you can add `noHistory`. See here: http://stackoverflow.com/questions/2550099/how-to-kill-an-android-activity-when-leaving-it-so-that-it-cannot-be-accessed-fr – Al Lelopath Mar 21 '16 at 19:47
  • I'm trying but is not working – Álvaro Koke Mar 21 '16 at 19:52
  • 1
    can you clear up what you're doing? If you have your activity open and you press the button to view all the apps you want your app to be destroyed? – Pztar Mar 21 '16 at 20:01
  • 1
    I somewhat understand better, where do you currently have the code above? – Pztar Mar 21 '16 at 20:42
  • @Pztar that is the thing... I don't know exactly where to put it, because my first activity (not te one with the count down, the one from where i call it) is ALSO called in the onStart() of a third activity (the main one). So i have 3 activities: 1 Activity) -> calls second in the onStart() 2 Activity) -> call third 3 Activity) -> the one with the countdown. When it finishes i want to shut down everything. – Álvaro Koke Mar 21 '16 at 21:50

3 Answers3

1

Just add android:noHistory="true" in your manifest file under the activity you want to behave that way.

http://developer.android.com/guide/topics/manifest/activity-element.html#nohist

Pztar
  • 4,274
  • 6
  • 33
  • 39
  • @ÁlvaroKoke based on your new edit, make sure you add the above to both of your activities, that means not under the `` tag but under both say `MainActivity` and `SecondActivity` or whatever it is in your case – Pztar Mar 21 '16 at 20:46
0

Try this: Runtime.getRuntime().exit(0);

e-shfiyut
  • 3,538
  • 2
  • 30
  • 31
FriendlyMikhail
  • 2,857
  • 23
  • 39
0
android.os.Process.killProcess(android.os.Process.myPid());
Nicolas Charpentier
  • 1,088
  • 1
  • 10
  • 21
  • not working, i can still see my app in the open ones. – Álvaro Koke Mar 21 '16 at 19:54
  • While this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value. – Ajean Mar 22 '16 at 00:14