onActivityResult method not being called Android

前端 未结 9 1716
误落风尘
误落风尘 2020-12-08 07:58

I am trying to send data from child activity to parent. But somehow, onActivityResult(..) is not getting called. here is code

Parent activity

selecte         


        
相关标签:
9条回答
  • 2020-12-08 08:14

    Use singleTop instead of singleInstace as launchMode as it maintains the activity in the same task.

    0 讨论(0)
  • 2020-12-08 08:14

    onPause was effecting onActivityResult.

    One of the corner case might be:
    my case was different and silly: The problem was in onPause, finish called and end the activity. Removed that and works well.

    @Override
    protected void onPause() {
        super.onPause();
        finish(); // this line causing the issue removed it. 
    }
    
    0 讨论(0)
  • 2020-12-08 08:16

    I found the mistake. I had below line in manifest.xml for child acitivity.

            android:launchMode="singleInstance"
    

    after removing this line. it's working like a charm!!!

    Thank You all for your input and suggestions.

    0 讨论(0)
  • 2020-12-08 08:17

    Not sure if this is your case, but when starting the child activity make sure you use startActivityForResult(intent), instead of startActivity();

    0 讨论(0)
  • 2020-12-08 08:18

    For anyone stuck with same problem, a symptom not to receive onActivityResult, following cases can cause this issue.

    • check you are using startActivityForResult() correctly, do not use startActivity().
    • if you do something in overriden onBackPressed method, super.onBackPressed(); has to be positioned at the last of the method, not at the first line. (my case to spend 5 hours)
    • remove android:launchMode="singleInstance" in manifest or equivalent argument to create a intent.
    • remove noHistory="true" in manifest of the callee activity.
    • check setResult() is missed.
    • finish() is called to close the activity. use finishActivity() to close callee activity.
    • use requestCode more than zero. negative value does not work.
    0 讨论(0)
  • 2020-12-08 08:19

    My case was a little bit complex and I realized that I used by error a static reference pointing to the first instance of the buttons listeners in a sub activity.

    At the first turn it was working, but when the user was returning from the parent activity, onActivityResult was not called.

    Replacing the static references was the fix

    0 讨论(0)
提交回复
热议问题