i use startActivityForResult for two activities like this
Activity A -> startActivityForResult(ActivityB,0)
-> Activity B -> setresult(10); finish();
-> Activity A -> if(result==10) {
dofunction();
}
but i must use this logic for 4 or more activities.
Activity A -> startActivityForResult(ActivityB,0)
-> Activity B -> finish();
-> Activity C -> finish();
-> Activity D -> setresult(10); finish();
-> Activity A -> if(result==10) {
dofunction();
}
but this does not work.
SOLUTION:
Activity A -> startActivityForResult(activityB,0);
Activity B -> activityCintent.setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT); startActivity(activityCintent); finish();
Activity C -> activityDintent.setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT); startActivity(activityDintent); finish();
Activity D -> setresult(10); finish();
Activity A -> if(result==10) {dofunction(); } YEPPP
this is the logic of FLAG_ACTIVITY_FORWARD_RESULT. First you start an activity for result, new activity sends this intent to another new activity until you set result. I hope this will be helpful for people having same problem.
After naming activity in startActivityForResult(ActivityB,0)
we give request code for the specified activity ie; startActivityForResult(ActivityB,REQUEST_CODE_FOR_ACTIVITYB)
. with request code being any integer. Then in onActivityResult
check for each request code and implement your logic
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With