onActivityResult never called

后端 未结 9 823
梦谈多话
梦谈多话 2020-12-17 10:04

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

相关标签:
9条回答
  • 2020-12-17 10:43

    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 :)

    0 讨论(0)
  • 2020-12-17 10:45

    FriendPicker activity

    Intent intent = new Intent(FriendPicker.this, MoodPicker.class);
    startActivityForResult(intent, 2);
    
    
    @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:             
                 if (resultCode == Activity.RESULT_OK) {     //optional   
                Log.i("in OnActivityResult", "Activity Resut 2");                
                  }
                break;
        }
    }
    

    MoodPicker class

    Intent intent = new Intent(MoodPicker.this, FriendPicker.class);
            setResult(Activity.RESULT_OK, intent);
    finish();
    

    I had the same problem using onActivityResult(); cause i didn´t understand how this will be correctly applied, here you can find a good explanation how to use onActivityResult onActivityResult doesn't work?

    0 讨论(0)
  • 2020-12-17 10:48

    If I am reading this right, all the code referenced needs to be in "FriendPicker". In "MoodPicker" you need code like this that sets the result and ends itself:

    this.setResult(SUCCESS_RETURN_CODE, i);
    this.finish();
    

    Let me know if this helps...

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