2011-12-05 81 views
1

我已經看到了其他問題,但我想要的東西不同,更簡單(我認爲)。以編程方式清除緩存?

我有一個活動,點擊發送到的電子郵件地址,你已經輸入一個歡迎電子郵件使用Java郵件API。更具體地說,當它第一次運行時,用你的密碼和歡迎郵件發送地址輸入你的Gmail帳戶。現在,當我輸入一個錯誤的密碼時,就會創建一個異常,並要求輸入真實的密碼或用戶名。但是,如果我把我的真實的一個它再次要求我這樣做。另外,如果我把我的真正的一個,然後它繼續發送歡迎郵件。我怎樣才能解決這個問題?下面是一個示例代碼:

EmailValidator val = new EmailValidator();     

    Boolean a = val.validate(yemail); 
    Boolean b = val.validate(temail); 
    if (a == false || b == false){ 
     AlertDialog.Builder box = new AlertDialog.Builder(this); 

     // Set the message to display 
    box.setMessage("Please enter a valid email address!"); 

      // Add a neutral button to the alert box and assign a click listener 
    box.setNeutralButton("Ok", new DialogInterface.OnClickListener()  { 

       // Click listener on the neutral button of alert box 
    public void onClick(DialogInterface arg0, int arg1)    { 

    Toast.makeText(getApplicationContext(), "OK", Toast.LENGTH_LONG).show(); 
                    }     
                      }); 
          box.show(); 
           }// end if validating emails 
    if (a == true && b == true && ypass != null){ 
     try { // send mail 
      GmailSender sender = new GmailSender(yemail,ypass); // SUBSTITUTE HERE     
      sender.sendMail(
           "EMERGENCY", //subject.getText().toString(), 
           "hi",     //body.getText().toString(), 
           "[email protected]",      //from.getText().toString(), 
           temail //to.getText().toString() address where the mail is sent to 
          ); 

      } 
    catch (Exception e) { 
     AlertDialog.Builder box = new AlertDialog.Builder(this); 

     // Set the message to display 
    box.setMessage("Please Re-enter your Gmail username and pasword"); 

      // Add a neutral button to the alert box and assign a click listener 
    box.setNeutralButton("Ok", new DialogInterface.OnClickListener() { 

       // Click listener on the neutral button of alert box 
    public void onClick(DialogInterface arg0, int arg1) { 

       Toast.makeText(getApplicationContext(), "OK", Toast.LENGTH_LONG).show(); 
                    }     
                      }); 
          box.show(); 
         } // end catching Exception 

                } // try to send mail 

} 

回答

0

我希望這將對你有用...

+0

我使用了類似的功能,看是否從用戶輸入的是一個電子郵件地址,但我做的不要問這個。如果一個無效的gmail帳戶被給出了一個認證異常被拋出。然後是使用我的真正的Gmail帳戶和相同的消息放在我的屏幕前。所以第二次認證從未完成。這是我想糾正的事情! – dothedos

+0

然後我認爲你必須清除catche,如果無效的電子郵件地址給出。 – Umesh

+0

好吧,我們現在正在關閉。如何做到這一點programmaticaly?我不希望用戶干預!讓我們說點擊做!你能提供一個示例代碼嗎? – dothedos