0

i know that this question is asked many times, but really i can't understand the answer, i want to set button, when user click it i want to exit the application (also the carbage collector should remove the objects), and after exiting i want to go to the screen where the user found the application icon on mobile.

for exit i don't know what to do

for going to the screen where to find the application icon i tried like this

Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.addCategory(Intent.CATEGORY_HOME);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);

but doesn't work

Totti
  • 665
  • 5
  • 12
  • 26

2 Answers2

1

When you start that activity, it will effectively stop your application's foreground activities. Android is designed to NOT shutdown the app so that it may be restarted faster.

However, if you really really want to purge the app from memory, then what you want to do is kill exit() on the Runtime singleton : http://developer.android.com/reference/java/lang/Runtime.html#exit(int)

Philippe Girolami
  • 1,876
  • 1
  • 13
  • 15
  • and if i want to keep the activity in background? what should i do to just go to the screen where the icon of the application where? – Totti Jul 04 '12 at 15:37
1

use this method, this will make your application to go in backgroud and will open home/app_menu screen

moveTaskToBack(true); //  method available in activity

reference link

AAnkit
  • 27,299
  • 12
  • 60
  • 71