2015-08-22 102 views
0

有DrawerMenu,但我不能收上displayView我的選項可用的應用程序(爲5)如何關閉應用程序通過DrawerMenu安卓

可以請你幫我這個問題?

跟隨我的代碼

private void displayView(int position) { 
    Fragment fragment = null; 
    String title = getString(R.string.app_name); 
    switch (position) { 
     case 0: 
      //fragment = new HomeFragment(); 
      //title = getString(R.string.title_home); 
      break; 
     case 1: 

      break; 
     case 2: 

      break; 

     case 3: 

      break; 

     case 4: 

      break; 

     case 5: 
      SharedPreferences sp = getSharedPreferences(PREF_NAME, MODE_PRIVATE); 
      SharedPreferences.Editor editor = sp.edit(); 
      editor.clear().commit(); 

      finish(); 

     default: 
    } 

回答

0

與其說finish()你應該使用這個代碼:

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

你會向用戶發送到主頁。