0

I make a non-stop background service for Android app, my solution is to send a broadcast to the registered receiver on the method OnTaskRemoved :

Background Service

and start the service again on the received: Broadcast Receiver

But it only works on Android 6 and 7, not on 5 and 5.1. Anyone knows how to deal with it, please help me, thanks a lot.

Omar Shawky
  • 1,242
  • 1
  • 12
  • 25
  • 1
    please share your code as text instead of this images so people could copy and debug it easily. – Omar Shawky Sep 11 '21 at 17:51
  • You need to check the if statement. Which line of the code make the service do not restart? – Wendy Zang - MSFT Sep 13 '21 at 08:26
  • @WendyZang-MSFT you can check the OnTaskRemoved function, I SendBroadcast but it doesn't work, the service still be stopped – Trần Kha Sep 13 '21 at 09:23
  • Try to start the service explicitely. Do something in OnTaskRemoved function like what you do in OnReceive method. Code: `Intent broadcastIntent=new Intent(context, typeof(class));` Or you could explicitly provide the package in an implicit intent. Please check the code in the link below. https://stackoverflow.com/questions/27183164/android-l-api-21-java-lang-illegalargumentexception-service-intent-must-be – Wendy Zang - MSFT Sep 14 '21 at 08:46

0 Answers0