When I switch from ActivityA
to ActivityB
I need to do a bit of background processing on a Bitmap
from ActivityA
(maybe a few seconds' worth) before it shows up in ActivityB
. Rather than delay the launch of ActivityB
and make my app feel sluggish I'd like to launch it immediately and have it make use of the Bitmap
as soon as the processing is finished (the user can do useful things in ActivityB
before the Bitmap
is ready).
The standard answer for receiving data from long-running processes seems to be a retained, non-UI Fragment
, which works great if your Activity
gets destroyed then re-created, but what about where you switch to a different Activity
? Even retained, non-UI Fragment
instances appear to be associated with a particular Activity
class, even after the Activity
itself is destroyed, and it appears that calling FragmentManager.findFragmentByTag(String tag)
from an instance of ActivityB
will fail to retrieve a retained, non-UI Fragment
created in ActivityA
.
Is FragmentManager.findFragmentByTag(String tag)
supposed to work from an instance of a different Activity
and I'm just doing something wrong? Or is there some other technique recommended in this situation?
A Service
feels like overkill here, but maybe I'm wrong and frequent creation/destruction of Service
instances is perfectly acceptable in Android apps (in which case my question is: why bother with a retained, non-UI Fragment
ever?)