2013-04-09 64 views
0

page.When在正確的用戶登錄,我想表明一個警告對話框說你的登錄信息已經verified.Click繼續proceed.Now我想這個,我有一個登錄後顯示的警告對話框警報對話框在登錄後顯示在下一個活動頁面上。 這裏是警告對話框代碼 - :只有特定活動頁面

SharedPreferences設置= getSharedPreferences(PREFS_NAME,0); 布爾型dialogShown = settings.getBoolean(「dialogShown」,false);

 if (!dialogShown) { 
      AlertDialog.Builder builder = new Builder(Myperwallet.this); 
      builder.setTitle("Fast Cashier!"); 
      builder.setMessage("Logging In"); 
      builder.setPositiveButton("Continue", new DialogInterface.OnClickListener() { 
       @Override 
       public void onClick(DialogInterface dialog, int which) { 
        dialog.cancel(); 
     //continue activity here.... 

       } 
      }); 

      builder.create().show(); 
      // AlertDialog code here 


    } 



     SharedPreferences.Editor editor = settings.edit(); 
     editor.putBoolean("dialogShown", true); 
     editor.commit(); 

我嘗試這樣做,但是當我按我已經登錄out.I需要知道如何設置該標誌爲真後,現在警報對話框不會顯示註銷button.Here是我的註銷按鈕的功能 - :

logout.setOnClickListener(new OnClickListener() { 
       public void onClick(View v) { 

       AlertDialog alertDialog = new AlertDialog.Builder(Myperwallet.this).create(); 
       alertDialog.setTitle("FastCashier:"); 
       alertDialog.setMessage("Are you sure you want to exit?"); 
       alertDialog.setButton(Dialog.BUTTON_POSITIVE, "Yes", new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int which) { 

         Intent logout = new Intent(Myperwallet.this,Login.class); 
         startActivity(logout); 

        } 
        }); 

       alertDialog.setButton(Dialog.BUTTON_NEGATIVE, "NO", new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int which) { 

         dialog.cancel(); 

        } 
        }); 

       alertDialog.show(); 
       } 
      }); 
+1

您需要爲在第二活動重新編寫代碼 – Pragnani 2013-04-09 07:14:40

回答

0

您需要添加一些實現到您當前的代碼。
你可以在sharedPrefs中保留一個標誌,並且最初它會是真的。第一次顯示它後,將其設爲假。
這是你現在必須實施的。

所以要再次顯示後旗註銷重置爲真,當用戶已註銷。所以當你到達活動時,對話框會顯示出來。

+0

嘿,甜心,你可以告訴我,我該如何重置標誌?請參閱我上面編輯的代碼。 – user218554 2013-04-09 08:03:39

0

實際上無法獲得下站着更多的問題,但你要表現出你的AlertDialog在一些OptionnaleRequirement如當Login那麼它表明在接下來的頁面是Required但由於SharedPreferences在應用程序的開始只顯示一次。當我註銷然後登錄時,我沒有得到任何alert dialog

SharedPreferences做什麼是存儲您的特定斯汀與關鍵,你需要與它匹配。 loing suceessufully後,你需要UpdateSharedPreferences與一些新的字符串,並需要與它匹配。

您也可以使用File檢查isExit()與否,並編寫要求將它釘住並讀取並與您匹配,並要求條件顯示alert dialog。這可能會幫助你。

0

跟蹤活動流程,也就是說,當你啓動你的應用程序時,它正在執行onCreate方法中的任何操作,對於創建方法中的問題集標誌,以及當你從任何其他活動切換到這個落實重新啓動(方法),並清除烏爾以前的數據.... 這樣的...

protected void onRestart() { 
    // TODO Auto-generated method stub 
    super.onRestart(); 

    //ur code 
} 

希望這會有所幫助,