Android--Service two boot mode StartService and Bindservice

Source: Internet
Author: User

Following the previous article, the use of Android–service, let's continue to look at two ways to start service

The first kind of startservice

。
Run the code and know the following conclusions:

  1. We understand that its start-up cycle is Oncreate->onstartcommand,
  2. After exiting the app, the service process in the background still exists and is not destroyed
  3. When I clicked on multiple StartService, I clicked 3 times and you found that the OnCreate method was created only once.
  4. StopService,
The second kind of bindservice

Run the code to learn the following conclusions:

  1. Click Bindservice, Life cycle oncreat->onserviceconnected
  2. Exits the current application, throws an exception, and shuts down the service,
  3. Click Unbindservice,
Attention

StartService and Bindservice buttons are all clicked
Then we can't turn the service off when we hit StopService or Unbindservice.
Need to Unbindservice first, then StopService.

Android--Service two boot mode StartService and Bindservice

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.