2016-09-29 48 views
-5

在我的應用程序中,我不想在導航抽屜菜單上單擊相同活動時的活動。如何防止導航抽屜菜單單擊時的重新創建活動

用戶在導航抽屜項目點擊地圖重新加載後的地圖活動。我不想重新加載地圖或刷新活動。

private void displayView(int position) 
{ 
    switch (position) 
    { 
     case 0: 

      break; 

     case 1: 
      Intent intent1 = new Intent(this, Activity1.class); 

      startActivity(intent1); 
      //finish(); 
      break; 


     case 2: 
      Intent intent2 = new Intent(this, Activity2.class); 
      startActivity(intent2); 
      finish(); 
      break; 

     case 3: 
      Intent intent4 = new Intent(this, Activity3.class); 
      startActivity(intent4); 
      finish(); 
      break; 

     default: 
      break; 
    } 
+1

1)請出示你的代碼。 2)菜單應該是裝載片段,無法啓動活動 –

+0

在我的代碼,我使用的活動不片斷 –

+0

好吧,請[編輯]你的問題,包括代碼 –

回答

1

您可以添加以下到您的功能

private int current=-1; 
    private void displayView(int position) 
    { 
     switch (position) 
     { 
      case 0: 
      current =0; 
      break; 

     case 1: 
      if(current!=1){ 
      current =1; 
      Intent intent1 = new Intent(this, Activity1.class); 

      startActivity(intent1); 
      //finish(); 
      } 
      break; 


     case 2: 
      if(current!=2){ 
      current=2; 
      Intent intent2 = new Intent(this, Activity2.class); 
      startActivity(intent2); 
      finish(); 
      } 

      break; 

     case 3: 
      if(current!=3){ 
      current=3 
      Intent intent4 = new Intent(this, Activity3.class); 
      startActivity(intent4); 
      finish(); 
      } 

      break; 

     default: 
      break; 
    } 
+0

thhks Mohammad Haidar –

+0

@MaheshGawhane請接受我的回答,如果它適合你 –

+0

我發現我自己的答案這不適合我... thnks –

相關問題