onActivityResult never called

2019-01-25 04:57发布

So far, I used the startActivity function with success and now that I need to use the startActivityResult, I have a problem.

When using this function, the activity I expect to be launched is launched correctly but it seems like the onActivityResult function is never called.

Here is my code in the FriendPicker activity, to lauch the MoodPicker activity:

Intent intent = new Intent(FriendPicker.this, MoodPicker.class);
startActivityForResult(intent, 2);

And here is my code in the MoodPicker activity:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent)
{                   
    super.onActivityResult(requestCode, resultCode, intent);

    Log.i("in OnActivityResult", "Activity Result");                        

    switch (requestCode)
    {
        case 2:             
            Log.i("in OnActivityResult", "Activity Resut 2");                

            break;
    }
}

and nothing in my logfile is written (I of course, checked that my log file was working properly and double check with a text view output).

Is there something I forgot to declare in the Manifest file?

Thanks in advance.

9条回答
地球回转人心会变
2楼-- · 2019-01-25 05:57

The mistake that I had made was that after creating my Intent I was calling startActivity() instead of startActivityForResult()

Sometimes the simple ones kill you :)

查看更多
萌系小妹纸
3楼-- · 2019-01-25 05:58
android:noHistory="true" 

like

android:launchMode="singleInstance"

will stop onActivityResult from receive result.

查看更多
仙女界的扛把子
4楼-- · 2019-01-25 06:00

I had same problem and solved it: Just remove

android:launchMode="singleInstance"
查看更多
登录 后发表回答