M
M
mitaichik2018-05-02 17:32:26
Android
mitaichik, 2018-05-02 17:32:26

How to continue running an operation after the application terminates?

In general, there is an operation (usual rx.Observable), the result of which I need to notify the user. I store the operations in a separate object tied to the application instance (more precisely, it is a Singletone in Dagger)
If a certain activity is open, then it subscribes to the observable and changes the UI as a result.
If not - I make a message using NotificationManager.
But if the user closes the application, then nothing happens. How to make the operation continue and even if the application is closed - I could show the Notification?
As I understand it, the Service needs to be involved here, well, another question arises: The operation can change the state of other singletone objects (also in dagger) - and if you do a Service, then I need these singletons to be the same instances in Application and Service . This is real?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Zagaevsky, 2018-05-02
@zagayevskiy

The service can extend the life of the application, but there are no guarantees. In addition, there is also Doze mode, and everything is generally bad there. But you can try. On the topic of singletons in dagger - well, the service lives within the same application, what's the problem?

S
Sergey, 2018-05-03
@red-barbarian

As if the system itself decides who to kill and who to live. And when. (Usually depends on resources)
Foreground processes live the longest. The ones in the foreground. (for example, in this process, the activity with which the user interacts works).
If there are not enough resources, then they are killed last.
Least of all Empty Processes - they have no active components. But at the same time, the system may not kill them (save for the sake of caching).
it is possible to raise your process to the foreground level through the service and startForegroud.
https://medium.com/google-developers/who-lives-and...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question