onActivityResult() Intent data is always null

前端 未结 3 509
耶瑟儿~
耶瑟儿~ 2021-02-12 03:16

Can somebody tell my why the Intent data is always null?

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          


        
3条回答
  •  温柔的废话
    2021-02-12 04:01

    Posting here as a possible answer though may not be your issue exactly

    Ensure your activity returning passes back something like this:

    Intent returnIntent = new 
    returnIntent.putExtra("result", app);
    returnIntent.putExtra("element", element);
    if (app.getStatus() == 2){
        returnIntent.putExtra("update", true);
        // Tell the parent that everything went okay
        setResult(Activity.RESULT_OK, returnIntent);
        Log.i(TAG, "Returning, Result Success");
    } else {
        // Tell parent that nothing changed
        setResult(RESULT_CANCELED, returnIntent);
        Log.i(TAG, "Returning, Nothing changed");
    }
    finish();
    

    I spent a long time suffering from null intents being returned. For me it was because in onBackPressed I was calling super.onBackPressed() before the above code. When I put it after everything worked great. If onStop/onDestroy is called too early the opportunity to pass an intent back is blocked. This may be your issue

提交回复
热议问题