Activity and thread Lifecycle

Source: Internet
Author: User

=============== Problem description ====================


Because the mobile phone needs to regularly send data to the server, a new thread is added in the activity, and the thread regularly sends data. Therefore, I would like to ask a question. If the activity is overwritten by other programs, that is, when the activity is in the Stop State, will the thread still work?

============= Solution 1 ======================


Of course, services are used. If a component-based service is bound, the corresponding services will be recycled after the corresponding components are recycled. Therefore, you can call the service method to start a service. That is to say, do not bind a component to the service area. The component is only used to enable the Service, so that the system will not recycle it, unless the system forcibly recycles them, or explicitly calls the stopself () function.

============= Solution 2 ======================


The thread will die unless the process of the thread is dead. Your app exits, and the thread may still be running.

============= Solution 3 ======================


We recommend using service. Why thread?

============= Solution 4 ======================


The process does not die. The thread can exist.

Activity and thread Lifecycle

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.