Android Service OnCreate when the UI thread is using Service, when to use thread

Source: Internet
Author: User

Han Mengfei sha Han Yafei [email protected] yue31313 Han_meng_fei_sha

Each method of the service's life cycle is in the main thread. The operation here can cause the main thread to block.

These methods, as well as callback methods, are oncreate those callback methods. Note the difference between the callback method and the general method. Because many people are difficult to understand the literal term of the callback. I don't know what the hell it is.

Service as one of the four components of Android, you may use it often. When it comes to it, we casually say that it will perform long tasks in the background, but is that really the right statement?

Although the service is executed in the background, it is still running in the main thread.

Let's not associate the background with the sub-threads, which is two completely different concepts. The background of Android is that it runs completely independent of the UI. Even if the activity is destroyed, or the program is closed, the service can continue to run as long as the process is in progress.

When to use service, when to use thread

1. If you only need to perform background tasks and do not need to interact with the user interface, you can use the service at this time;
2. If you need to perform tasks on the main thread, and when you need to interact with the user interface, you can choose to create a new thread instead of a service.

Android Service OnCreate when the UI thread is using Service, when to use thread

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.