The androidapp automatically restarts after the APP is cleared in the Android background.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.