Can I update UI / Views (like changing a textviews text) while a activity is paused, for example, because another activity has been started?
I have implemented a little test app that do something like this, by connecting activities with an eventbus.
Activity A has a TextView. Activity A registers itself to the EventBus in onCreate() and unregisters itself in onDestroy(). Activity A starts Activity B. Activity B does some changes and fires a ChangedEvent. This ChangedEvent will be received by Activity A, because its still registered even if Activity A is paused and will update the TextView of Activity A (changing the text).
Everything works fine. I have tested this on various nexus devices and emulators on various Android versions (2.3.3 up to 4.3). No Exceptions or unexpected behavior.
So is it safe to say, I can build an App with an Activity that updates his View while the activity is paused? Does it depends on manufacturer etc? I could test my sample app only on stock android devices.
resumed: The activity is in the foreground and the user can interact with it. paused: In this state, the activity is partially obscured by another activity—the other activity that's in the foreground is semi-transparent or doesn't cover the entire screen.
Paused – An activity is in a paused state when the activity is visible but not in focus. Stopped – An activity is in a stopped state when it's no longer visible. It is still in memory, but it could be destroyed by the android runtime, as “stopped” activities are generally considered low priority.
In an Android device, go to Settings> Google> Personal info & privacy> Activity controls> Web & App Activity and turn off the Web & App Activity.
Yes, you can count on this working.
Views don't actually care about the lifecycle of the Activity that owns their window. (You can add other views directly to the WindowManager outside of an Activity's lifecycle altogether.)
Unless an Activity is actually destroyed (and of course as long as your process isn't killed), a record of its window and views sticks around. If the window is still visible, updates to the views within it will also be visible even if the Activity is paused.
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