The androidapp automatically restarts after the APP is cleared in the Android background.
Recently solved an Android APP bug and found that the APP automatically restarts after it is cleared in the background. This is a strange phenomenon. After the background cleaning of some mobile phones (HTC), the program will restart again, while some mobile phones (Xiaomi) will not. It may be because Xiaomi's mobile phone is working internally. After the background is cleaned up, the corresponding APP will not be restarted.
Debug finds that there is a Service in the APP. In the onStartCommand function of the Service, the returned value is an int. The two main values are START_STICKY and START_NOT_STICKY. START_STICKY indicates that if the service process is killed, the service State is retained to the starting state, but the intent object to be delivered is not retained. Then the system will try to re-create the service. Because the service status is starting, the onStartCommand (Intent, int, int) method will be called after the service is created. If no startup command is passed to service during this period, the Intent parameter is null. START_NOT_STICKY is "non-viscous ". When this return value is used, if the service is kill abnormally after onStartCommand is executed, the system will not automatically restart the service.
Our program sets START_STICKY. When the program restarts, some variables are not initialized, resulting in crash. After START_NOT_STICKY is changed, the problem is solved. However, there is still one problem left. The APP that the boss found, whether on HTC or Xiaomi machines, is still running its services after the background is cleaned up. This is strange, as my colleague guessed, it may be because a whitelist is set for a specific program in the ROM of the mobile phone. I personally think it is unlikely, but the problem is, if all APP coder can set the program to not be killed, why is it just not killed? Or is our technology too hard to find a way to stop being killed by the system?
In short, the Android system is so messy and apple is a great way to do things.