Reputation: 3926
I have 3 activity A , B and C
Flow is:
Activity A calls B , B Call C. (A -> B -> C )
Now I am in Activity C and want to return some result to Activity A without involving B.
Scenario is Activity B should be call only by A ( if user press back button from C , B will not be call and activity A will comes in front).
Any one let me know how to deal with this situation.
Update :
I am calling activity B from A
Intent intent = new Intent(this, B.class);
startActivityForResult(intent, 0);
in same way I am calling C from B.
In A i am over riding onActivityResult
method
Upvotes: 3
Views: 840
Reputation: 34026
StartActivityForResult
from ActivityA.StartActivityForResult
from ActivityB. Don't finish ActivityB
.set the result
.OnActivityResult()
set the result to ActivityA and finish ActivityB.onBackPressed()
and set the result null and finish the ActivityCUpvotes: 2
Reputation: 109257
I think you have to call Activity C from B by startActivityForResult()
and then in Activity B override onActivityResult() and put finish()
; Also from Activity A start Activity B by startActivityForResult()
This will direct to Activity A without reCreated it.
Upvotes: 1
Reputation: 35986
This is simple way u do
in Acvtivity C
Intent i=new Intent(getApplicationContext(), A.class);
i.putExtra("id", id);
startActivity();
On backBtn Event
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
// do something on back.
Intent i=new Intent(getApplicationContext(), A.class);
i.putExtra("id", id);
startActivity();
return true;
}
return super.onKeyDown(keyCode, event);
}
Upvotes: 1