Android Service First Solution

Source: Internet
Author: User

What is the service?

The biggest difference between him and the activity is that he doesn't have a special layout display interface, and he works silently in the background of the app.

Although we do not need to use the service except in a few cases, it is also necessary to understand how the service is used

We know that activity due to its own shortcomings, if the activity has generated a jump, then the current activity will be completely stopped work.

But sometimes we want to continue other activities in the process of listening to the song, calling the phone, downloading the file, and then we should use the service, no matter how the front-end activity changes, as long as the service is not stopped, the service will continue his work.

The workflow flowchart for the service is as follows:

Use the service first to create a new class that inherits from the service

Next we need to register the service in the Androidmanifest.xml file


Let's look at two scenarios for invoking service services:

First, StartService

Second, Bindservice


The biggest difference between the two methods is that Bindservice will automatically unbind the service when the app exits, while StartService needs to terminate the services manually, so we need to choose the appropriate method to invoke

8844302

Android Service First Solution

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.