简体   繁体   English

永远不会调用onactivityresult()

[英]onactivityresult() is never called

I am trying to send mail from my app.The problem is after successful/unsuccessful delivery of the email it doesn't return to the activity, meaning that onActivityResult() is not being called. 我正在尝试从我的应用发送邮件。问题是成功/不成功发送电子邮件后,它没有返回活动,这意味着未调用onActivityResult()

Here is my code: 这是我的代码:

String[] recipients = {"soham@gmail.com"};
Intent email = new Intent(Intent.ACTION_SEND, Uri.parse("mailto:"));

// prompts email clients only
email.setType("message/rfc822");
email.putExtra(Intent.EXTRA_EMAIL, recipients);

try{
    // the user can choose the email client
    startActivityForResult(Intent.createChooser(email, "Choose an email client from..."), 1);
}catch(android.content.ActivityNotFoundException ex){

}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
    if(requestCode == 1){
        if(resultCode == RESULT_OK){

        }else if (resultCode == RESULT_CANCELED){
        }
    }
}

I have checked this but not working for me. 我已经检查过了,但没有为我工作。 Can anyone tell me what am I doing wrong. 谁能告诉我我在做什么错。

Edit 编辑

I got the problem.It will work fine in Activity.But it will not work on Fragment or FragmentActivity . 我遇到了问题。它在Activity中可以正常工作,但在FragmentFragmentActivity上不起作用。 All fragment is closing down forcefully.You can say my app is going on the background.How to solve this issue?Anybody got any idea. 所有片段都在强制关闭。您可以说我的应用程序正在后台运行。如何解决此问题?

If i uderstand your problem correctly; 如果我正确理解您的问题,

In your activity's onActivityResult part you can find your fragment 在活动的onActivityResult部分中,您可以找到片段

YourFragment fragment = (YourFragment)getSupportFragmentManager().findFragmentById(R.id.your_framelayout_id);

And use your fragment's public method: 并使用片段的公共方法:

if(fragment != null)
{
   fragment.yourPublicMethod();   
}

In yourPublicMethod you can do whatever you want. 在yourPublicMethod中,您可以做任何您想做的事情。 I hope this helps you. 我希望这可以帮助你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM