2011-12-05 137 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

相关问题