Cactusroot
Cactusroot

Reputation: 1058

Reference to AppCompatActivity object created via startActivity

I have got approximately this Activity construct:

MainActivity starts Activity2 startsForResult Activity3

Now I want to have the Activity result of Activity3 being send to the MainActivity. But to create the Intent, I need to have a reference to the MainActivity.

I tried:

Upvotes: 1

Views: 87

Answers (1)

Viks
Viks

Reputation: 1574

In your MainActivity

goToNextActivity(){
    startActivityForResult(intentActivity2, SOME_REQUEST_CODE);
}

onActivityForResult(...){
    doSomeStuffWithResult();
}

In your Activity2

goToNextActivity(){
    intentActivityC = new Intent(...);
    intentActivityC.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
    startActivity(intentActivityC);
}

do not forget to use FLAG_ACTIVITY_FORWARD_RESULT in Activity2

In your Activity3

goBackToActivityA(){
    setResult(someResultCode); //setResult send the data
    finish();
}

Upvotes: 1

Related Questions