2012-07-19 78 views
1
進度

,當我試圖退出,我運行下面的代碼,但我不能殺的進展,如何殺死在Android的

所以如果我重新啓動我的應用程序,另一個進步started.what事?

我退出代碼:

Intent startMain = new Intent(Intent.ACTION_MAIN); 
    startMain.addCategory(Intent.CATEGORY_HOME); 
    startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
    startActivity(startMain); 
    System.exit(0); 
    finish(); 
+0

爲uploding你需要增加你的信譽得分是圖像1現在...你需要爲了獲得使用此功能的特權,請在網站上註冊至少10個聲望的成員http://meta.stackexchange.com/questions/75491/how-to-upload-an-image-to-a-post – 2012-07-19 08:52:26

+0

這個活動是你的根源活動還是隻活躍在堆棧中? – 2012-07-19 08:55:46

+1

http://stackoverflow.com/questions/2092951/how-to-close-android-application – 2012-07-19 08:57:49

回答

0

使用此代碼來結束你的應用程序

finish(); 
     Intent intent = new Intent(Intent.ACTION_MAIN); 
     intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
     intent.addCategory(Intent.CATEGORY_HOME); 
     startActivity(intent); 
+1

非常感謝,它真的有效! – Stilo 2012-07-19 09:14:11

+0

爲什麼先調用finish()?在它開始另一項活動之前,這不會關閉活動嗎? – wojciii 2012-07-19 09:21:13

+0

是的,它會關閉活動,然後開始一個新的活動,清除頂部的標誌,活動堆棧將被清除,第二個標誌確保主屏幕,這樣所有進程將悄悄停止並且應用程序關閉 – vipin 2012-07-19 10:46:28