The issue of automatic restart of the program after the Android background cleanup app is resolved

Source: Internet
Author: User

Recently solved an Android app bug and found that the app was automatically restarted after being cleaned in the background. The phenomenon is very strange, some mobile phone (HTC) Backstage cleanup, the program must crash, and some cell phone (Xiaomi) program will not crash. When you look for a problem, you find that the HTC phone performs a background cleanup and the program restarts automatically, while the Xiaomi phone does not. Speculation may be the internal processing of millet phone, when the background cleanup, the corresponding app will not restart again. But the question is, why does the HTC phone background cleanup cause the program to crash.

Debug found that there is a service inside the app, in the service's Onstartcommand function, the return value is an int. The main two values are Start_sticky and start_not_sticky. The implication of Start_sticky is that if the service process is killed, the status of the reserved service is the start state, but the delivery intent object is not preserved. The system then tries to recreatethe service, and since the service status is started, the Onstartcommand (Intent,int,int) method must be called after the services are created. If no startup commands are passed to the service during this time, then the parameter intent will be null. And Start_not_sticky is "non-sticky". When this return value is used, the service is not automatically restarted if the service is killed by an exception after Onstartcommand is executed.

Our program is set to Start_sticky, the program timing restart, some variables are not initialized, resulting in crash. After changing to Start_not_sticky, the problem is solved. But there is still one problem, the boss found the app whether on the HTC or Xiaomi Machine, after performing a background cleanup, the service is still there, it is very strange, colleagues guessed that the phone ROM may be a specific program set up a white list. Personally, it's unlikely, but the question is, if all app coder can set the program to not be killed, why just not kill? Or our technology is not perfect, did not find the method of not being killed by the system?

In short, the Android system is very messy, or Apple Dafa good, we all behave according to the rules.

The program automatically restarts after the Android background cleanup app is resolved

Related Article

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.