我有一个注册屏幕,当用户完成注册后,会向他们发出警报以检查他们的邮件,并将其重定向到gmail。但是,Gmail崩溃了,它重定向回我的应用程序的登录屏幕。应用重定向是否正确实施?
//method that opens check email alert
public void showDialogForRegistrationSuccess(final Activity activity, String msg) {
final Dialog dialog = new Dialog(activity);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setCancelable(false);
dialog.setContentView(R.layout.custom_dialog_for_exception);
TextView text = (TextView) dialog.findViewById(R.id.text_dialog);
text.setText(Html.fromHtml(msg));
Button dialogButton = (Button) dialog.findViewById(R.id.btn_dialog_ok);
dialogButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
sendEmail();
finish();
}
});
dialog.show();
}
/**Method that opens email client*/
public void sendEmail() {
final Intent emailLauncher = new Intent(Intent.ACTION_VIEW);
emailLauncher.setType("message/rfc822");
try {
startActivity(emailLauncher);
finish();
} catch (android.content.ActivityNotFoundException ex) {
System.out.println("not working");
}
}
答案 0 :(得分:2)
首先,您要致电finish()
两次。从您的sendEmail()
方法中将其删除。
第二,由于您没有尝试通过应用发送电子邮件,因此请将sendEmail()
方法更改为:
public void sendEmail() {
Intent emailLauncher = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, Intent.CATEGORY_APP_EMAIL);
emailLauncher.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(emailLauncher);
}
在on the docs上了解更多信息。
答案 1 :(得分:2)
使用此
public void sendEmail(){
Intent mailIntent = new Intent(Intent.ACTION_VIEW);
mailIntent.setClassName("com.google.android.gm","com.google.android.gm.ConversationListActivity");
startActivity(mailClient);
}