我在点击Button
时尝试发送电子邮件,我想在发送电子邮件后转到应用的主页。我尝试了这段代码,但它没有用。我可以发送电子邮件,但之后我无法访问主页,我将转到发送电子邮件的同一页面。
public void onSendClick(View view) {
Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
intent.setType("Audio/mp3");
intent.putExtra(Intent.EXTRA_SUBJECT, "Attachment from app");
intent.putExtra(Intent.EXTRA_TEXT, "Sending mp3 file ");
intent.putExtra(Intent.EXTRA_EMAIL, new String[] {"email@example.com"});
ArrayList<Uri> uris = new ArrayList<Uri>();
uris.add(Uri.fromFile(new File(mFileName.getAbsolutePath())));
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
startActivity(Intent.createChooser(intent, "Send mail"));
/* Intent i = new Intent(SubmitActivity.this, MainActivity.class);
//i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
this.startActivity(i); */
}
答案 0 :(得分:2)
尝试使用startActivityForResult方法并导航到onActivityResult回调中的主页。在销毁电子邮件活动后调用onActivtyResult回调。
static final int EMAIL_REQUEST = 1;
public void onSendClick(View view) {
Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
intent.setType("Audio/mp3");
intent.putExtra(Intent.EXTRA_SUBJECT, "Attachment from app");
intent.putExtra(Intent.EXTRA_TEXT, "Sending mp3 file ");
intent.putExtra(Intent.EXTRA_EMAIL, new String[] {"xxx@yahoo.co.uk"});
ArrayList<Uri> uris = new ArrayList<Uri>();
uris.add(Uri.fromFile(new File(mFileName.getAbsolutePath())));
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
startActivityForResult(Intent.createChooser(intent, "Send mail"), EMAIL_REQUEST);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == EMAIL_REQUEST) {
//Navigate to home page from here.
}
}
答案 1 :(得分:0)
如果您参与了主页活动中调用的活动,请尝试
startActivity(..);
finish();