During the closure of the activation is not performed onActivityResult ()

@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); Log.e("TAG","Работает"); } 

So I run the next activation.

 Intent intent = new Intent(getApplicationContext(),Cart_level_1.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivityForResult(intent,1); 

We get the result

  if(!this.getClass().toString().equals("class ilhom4ik_app.com.girbar.main$1")) { Intent results = new Intent(); results.putExtra("res","go"); setResult(RESULT_OK, null); finish(); } 

But for some reason, onActivityResult () does not start

  • instead of getApplicationContext() pass in intent YourActivityName.this - Jarvis_J
  • This solution does not work ( - ILHOM4IK 4:05 pm
  • 2
    While it is not very clear that you do not work, but there are a couple of moments: why in setResult (RESULT_OK, null); pass null instead of your intent? Log.e - error logging, use Log.d for debugging. Although not relevant to your question. - Vladimir Yarovoy 5:14
  • The advice above is still correct - you do not need to transfer the context of your application to the intent, but rather you need to transfer the context to the activation. Replace with this or ActivityName.this. And the super method call in onActivityResult is not needed. - Vladimir Yarovoy pm

1 answer 1

Perhaps the condition is not true or the execution does not reach this code at all, but for this case you will not get any result.
The result must always be returned. To do this in onCreate running activity, call

  setResult(RESULT_CANCELED); 

Now that would not happen, the result will be "canceled".
If the task is successfully completed, you will redefine it with another result you need.