startActivityForResult(); [英] startActivityForResult();

查看:145
本文介绍了startActivityForResult();的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Intent emailSend = new Intent(android.content.Intent.ACTION_SEND);
        emailSend.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"tonikg90@gmail.com"});
        emailSend.putExtra(android.content.Intent.EXTRA_SUBJECT, "Item Best Seller");


        emailSend.putExtra(android.content.Intent.EXTRA_TEXT, map1.toString());
        emailSend.setType("text/plain");

        //startActivity(Intent.createChooser(emailSend, "Send Email..."));

        setResult(RESULT_OK, emailSend); 
        finish();
        break;

点击发送电子邮件按钮后,它应该去的电子邮件服务。但它立即返回到第一个活动。我怎样才能使其邮件服务,之后点击发送,则返回到第一个活动,也与吐司说:邮件已发送

after click sending Email Button, It's supposed to go to email service. But It immediately goes back to the first activity. How can I make it to mail service, and after click "send" then it returns back to the first activity, also with Toast says that "Email has been sent"

推荐答案

首先,请从 startActivityForResult 办法评论。记住:启动活动以异步方式工作,您使用startActivityForResult所以刚过,的setResult 完成将被执行

First, remove comment from startActivityForResult method. Remember: start activity works asynchronously, so just after you used startActivityForResult, setResult and finish will be executed.

您需要做的是什么,是落实的onActivityResult 方法,并移动的setResult 完成到那里。 的onActivityResult 当邮件已发送将被调用,从而将让你回到你的主要活动。

What you need to do then is to implement the onActivityResult method, and move setResult and finish to there. onActivityResult will be called when the email has been sent, thus it will get you back to your main activity.

这篇关于startActivityForResult();的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆