【问题标题】:Clearing cache programmatically?以编程方式清除缓存?
【发布时间】:2011-12-05 21:36:59
【问题描述】:

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

我有一个活动,点击发送到您使用 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(), 
                                "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

}

【问题讨论】:

    标签: android caching


    【解决方案1】:

    希望对你有用...

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

    【讨论】:

    • 我使用类似的函数来查看用户的输入是否是电子邮件地址,但我不问这个。如果给出了无效的 gmail 帐户,则会引发身份验证异常。然后是使用我真正的 gmail 帐户,并将相同的消息放在我的屏幕前。因此,永远不会完成第二次身份验证。这是我要纠正的事情!
    • 那么我认为如果提供了无效的电子邮件地址,你必须清除捕获。
    • 好的,我们现在接近了。如何以编程方式执行此操作?我不希望用户干涉!让我们说点击一下!可以给我一个示例代码吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多