以编程方式清除缓存?

时间:2011-12-05 12:41:58

标签: android caching

我已经看过其他问题,但我想要一些不同且更简单的东西(我认为)。

我有一项活动,点击发送到您使用java mail 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(), 
                                "stathias7@hotmail.com",                      //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

}

1 个答案:

答案 0 :(得分:0)

我希望这对你有用......

private boolean validMail(String emailstring) {
    Pattern emailPattern = Pattern.compile(".+@.+\\.[a-z]+");
    Matcher emailMatcher = emailPattern.matcher(emailstring);
    return emailMatcher.matches();
}