【发布时间】:2013-11-24 16:39:00
【问题描述】:
我是 android 编程的新手,我正在尝试开发一个简单的应用程序,我正在尝试使用如下所示的 try catch 块发送电子邮件:
new Thread(new Runnable() {
public void run() {
try {
GMailSender sender = new GMailSender("username@gmail.com","password");
sender.sendMail("Test mail","This mail has been sent from android app along with attachment","username@gmail.com","Someuser1@gmail.com");
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "Error",Toast.LENGTH_LONG).show();
}
}
}).start();
从上面的代码中,当电子邮件发送失败时,我使用 toast 显示错误。 但是现在我想知道如果邮件发送成功我需要显示吐司
这是我尝试过的,但应用程序崩溃并且无法显示任何 toast
new Thread(new Runnable() {
public void run() {
try {
GMailSender sender = new GMailSender("username@gmail.com","password");
sender.sendMail("Test mail","This mail has been sent from android app along with attachment","username@gmail.com","Someuser1@gmail.com");
Toast.makeText(getApplicationContext(), "Success",Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "Error",Toast.LENGTH_LONG).show();
}
}
}).start();
任何人都可以指导正确的方法来实现我的目标。
【问题讨论】: