0

I have 4 Activities A -> B-> C -> D

from Activity D I want to go back to B

here is the code

manifest:
<activity android:name=".GetAttendance" android:launchMode="singleTask"/>

.

Activity D
Intent intent = new Intent(AddNewGuest.this, GetAttendance.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    intent.putExtra("guest", temp);// temp is an object
                    setResult(600, intent);
                    startActivity(intent);

on Activity B, I am calling:

      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        System.out.println("requestCode:"+requestCode+"  resultCode:"+resultCode);
}

But I am getting the requestCode equals to 1000 where it I am sending it 600

However, when Activity B calls C and before going to D I'm setting requestcode to 1000 startActivityForResult(intent, 1000);

any suggestion?

SHADOW.NET
  • 555
  • 1
  • 5
  • 20

1 Answers1

0

You are sending a requestCode of 1000, which can be seen from your startActivityForResult(intent, 1000); statement

You were expecting a 600, but the call to setResult(600, intent); is setting the result code to 600

This is different because you are expecting for a request code, whereas the 600 value is for result code

https://developer.android.com/reference/android/app/Activity#setResult(int,%20android.content.Intent)

JoM
  • 545
  • 4
  • 11
  • OK, the resultCode returns as **0** – SHADOW.NET Nov 09 '18 at 20:26
  • A result code of 0 means cancelled, or you pressed back button or you did not set a a resultvalue. https://developer.android.com/reference/android/app/Activity.html#RESULT_CANCELED – JoM Nov 09 '18 at 20:28
  • Even when I return back from C to B I get reultCode=0 – SHADOW.NET Nov 09 '18 at 20:28
  • call setResult() , then call finish() not startactivity. Finish() will trigger the onActivityResult() callback of the previous screen – JoM Nov 09 '18 at 20:33
  • I am calling setResult(600, intent). and using startActivity() because finish() will return to the previous one `C` while I need to go to `B` – SHADOW.NET Nov 09 '18 at 20:36
  • Thanks for the try though – SHADOW.NET Nov 09 '18 at 21:01
  • try calling finish() from D then finish() from C, inside the onresultactivity. chaining the requestcodes and passing resultcodes from D to C until C to B. – JoM Nov 09 '18 at 23:02
  • I guess it is one way to do it but it is not the optimal one. Thank you – SHADOW.NET Nov 10 '18 at 11:18