Reputation: 2071
While this has been asked many times, I couldn't find an answer for my variation of the issue.
I have three Activities, A, B, and C
.
It is possible to get from A -> B
and it is also possible to get from A -> C
; it is not possible to get from B -> C
.
Once we're in Activity C
, the only way to get out of the Activity is by pressing the system back button or a call to onBackPressed()
by pressing the back button in the Toolbar. I never create another Intent to launch from C
. Because I never create an Intent, I have no way of calling intent.putExtra(key, value);
I'm trying to implement a condition refresh of some data in A
--but only if we're coming back from B
. How can I accomplish this?
Upvotes: 3
Views: 2326
Reputation: 7479
You can use EventBus for easy communication between activities, services, fragments etc. It's really easy to use, and it can accomplish what you're asking easily.
You will just need to post a certain event in let's say Activity B's
@Override onBackPressed()
Or wherever it feels appropriate. Eventbus is a great tool and you should learn to use it, it will benefit you greatly.
EDIT: I just remembered a quick fix that I do not recommend since using EventBus is better in the long run.
You can put one value in the shared preferences in activity B's onStop, and the other value in activity C's onStop and then fetch that value in activity A's onResume. I'm not certain this would work, but I see no reason why it wouldn't.
Upvotes: 1