0

I have two activities 1. MainActivity (launchMode is standard) 2. SecondActivity (launchMode is singleTask)

When I am calling SecondActivity from MainActivity, MainActivity's onActivityResult being called before onCreate of SecondActivity.

Intent intent = new Intent(MainActivity.this,SecondActivity.class);
startActivityForResult(intent, 115);

Here is the onActivityResult() of MainActivity.

 public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { 
     super.onActivityResult(requestCode, resultCode, data); 
     //It is giving requestCode = 115, resultCode=0, without calling setResult anywhere.
 }

Then it is coming to onCreate() of SecondActivity.

I have read that, this is a bug of android in the below link. onActivityResult() called prematurely

Is there any solution so far, I need launchMode to be singleTask for my SecondActivity.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
kiran puppala
  • 689
  • 8
  • 17
  • from the docs: *"The resultCode will be RESULT_CANCELED if the activity explicitly returned that, didn't return any result, or crashed during its operation."* - so what case was it? did you have any crash? – pskink May 26 '19 at 07:06
  • I didn't get any crash it just goes to onActivityResult() with resultCode RESULT_CANCELLED i.e., 0 – kiran puppala May 26 '19 at 07:16
  • [This answer](https://stackoverflow.com/a/3546419/6698642) is in the question you linked, and it has been accepted. Have you tried this? Did it not work for you? – shriakhilc May 26 '19 at 07:18
  • @TheGamer007, The answer suggests to change launchMode to singleTop which in my case is not possible. I need to use singleTask – kiran puppala May 26 '19 at 07:21
  • post your `SecondActivity` code then – pskink May 26 '19 at 07:22
  • please check your other code, problem could be somewhere else, as it seems fine. – Asad Ali Choudhry May 26 '19 at 09:06

0 Answers0