I know how to send data from an activity to the Next Activity
: [Intent.putExtra(key, value);
].
I also know how to return from an activity to the previous one and include data: [see this stackoverflow answer].
What I want to know however is, how I can return to the Home Activity and include data. As an example:
- I start the app in Activity A and do some stuff
- Then I go to Activity B and do some stuff
- Then I go to Activity C and do some stuff
- And then I want to return to Activity A (and do different stuff)
In step 4 I want to do something different than normally in the onResume (or another method it returns to), so the data I include is a boolean with a key (preferably using intent.putExtra("myKey", true);
(or false if something failed)). In the onResume I then do something like:
@Override
protected void onResume(){
super.onResume();
if(intent.getExtras() != null && intent.getAction().toString().equals("myKey")){
if(intent.getExtras().getBoolean("myKey")){
// do something else (step 4) on success
}
else{
// do something else (step 4) on fail
}
}
else{
// Do regular stuff I normally do in the onResume()
}
}
Ok, I think I've have solved my problem. My HomeActivity already is a BroadcastReceiver, so I just send an intent from my last Activity to my HomeActivity using the Broadcast..
Will test this to see if it works. Though I'm kinda doubting it will when I'm in another Activity. (My HomeActivity is already a BroadcastReceiver for some Http-requests I've had to send and needed the result of, which are AsyncTasks of course.)
Ok, this doesn't work when I'm not already in the MainActvity. So more suggestions are welcome..