0

I do have a background service launched by an activity:

startService(new Intent(this, tsServico.class));

The service launch a new thread and return START_STICK:

tsApp DW = new tsApp();
new Thread(DW).start();
return START_STICKY;

The tsApp is a class:

public class tsApp extends Service implements Runnable { ...

Everything works fine, until the activity is destroyed (like when removed from the recent app list). When it happens it seems that the thread is being killed. I can see at Developer's Options > Running Services, that the service is running.

How can I keep that thread running?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Thiago Souza
  • 135
  • 2
  • 8
  • https://stackoverflow.com/q/12219249/3166697 – Dima Kozhevin Oct 24 '17 at 19:51
  • Keep in mind that removing the app from the recent app list is *not* the same as an `Activity` in your app being destroyed. When the app is removed from the task management (recent app) list, the process is killed. That means all components (including services) are destroyed. Use the BACK button to exit your `Activity` and you'll see that your process sticks around and so does the thread of interest. – Larry Schiefer Oct 24 '17 at 19:58
  • Thanks. But when WhatsApp ia removed from the recent app list it still receive messages. – Thiago Souza Oct 24 '17 at 20:04
  • It is most likely using a push notification service, such as FCM. Those are delivered by the system and will re-start the app process, if needed. – Larry Schiefer Oct 24 '17 at 20:30

0 Answers0