Reputation: 47945
I have a Application implementation where I do some heavy tasks in the background, which might been better in a service but this does not matter for this question.
However I have the problem that I need to know why the Application was started. Like through a normal intent (where the intent is also interesting but this is optional) or if the app is only stated for a backup or recovery operation. In the last case I can omit much things I would need for a normal start.
How can I detect why my Application implementation was started (Intent vs. backup/recovery)?
Upvotes: 1
Views: 712
Reputation: 1006724
However I have the problem that I need to know why the Application was started
That is not possible, sorry. Whatever is started can then tell the Application
why it was started, but the Application
has no great way of determining that independently, any more than would any other singleton.
I have a Application implementation where I do some heavy tasks in the background, which might been better in a service but this does not matter for this question.
Actually, IMHO, it does. The Application
object is created in every process, just after any of your ContentProvider
s (if any). I find it disturbing that you would start doing "some heavy tasks" just because the process starts, while the process is starting. In many cases, that's a very important time for your UX, and tying up gobs of CPU time right at that moment is not a good idea.
Having this work be done by a service, on the other hand, gives you flexibility on timing. It also serves as a marker to the OS that you are doing these "heavy tasks", without which Android can terminate your process at will once it is no longer in the foreground.
Upvotes: 1