2010-12-19 59 views
0

如何關閉apk或換句話說退出APK。我嘗試完成,但它只是關閉當前的活動,我需要關閉所有的活動在apk中?關閉或退出問題apk

+0

不要這樣做。它違背了Android UI準則,是開發人員對編寫行爲良好的Android應用程序不感興趣的用戶的第一個信號。請參閱下面鏈接的Reto Meier帖子。 – adamp 2010-12-19 18:08:35

回答

0

這被問了很多次,但我現在找不到鏈接。和我以前一樣回答:

短: 你不應該。 閱讀雷託·梅爾的關於主題的意見:When to Include an Exit Button in Android Apps (Hint: Never)

長:

protected Dialog onCreateDialog(int id) { 
     Dialog dialog = null; 

     switch (id) { 
     case MENU_QUIT: 
      AlertDialog.Builder builder = new AlertDialog.Builder(this); 
      builder.setMessage(getString(R.string.main_screen_quit_text)) 
        .setCancelable(false) 
        .setPositiveButton(
          getString(R.string.main_screen_quit_yes), 
          new DialogInterface.OnClickListener() { 
           public void onClick(DialogInterface dialog, 
             int id) { 

            moveTaskToBack(true); 
           } 
          }) 
        .setNegativeButton(getString(R.string.main_screen_quit_no), 
          new DialogInterface.OnClickListener() { 
           public void onClick(DialogInterface dialog, 
             int id) { 
            dialog.cancel(); 
           } 
          }); 
      AlertDialog alert = builder.create(); 
      return alert; 
     default: 
      dialog = null; 
     } 
     return dialog; 
    } 
2

應用程序是活動只是鬆散的聯合會,而且也沒有的「退出應用程序」內置到Android的概念。如果你想做一些模擬退出的事情,你必須手動跟蹤哪些活動仍然存在,並且每個列表中都有一個finish()

最好在沒有「退出」概念的情況下設計您的應用程序,並讓系統根據需要銷燬其部件。這符合Android的設計原則之一,即用戶可能希望返回到他所離開的應用程序,而無需延遲完全重啓。如果您的活動中有某些內容需要停用,請利用活動生命週期,並採用適當的方法進行操作。