Android development use action to start/close service

Source: Internet
Author: User

It is useful to use intent to control Service

The parameter used is the class of the service

There is another way to control the startup/shutdown of a service

Parameters for incoming action via intent




Register a service in manifest and set an action

<service     android:enabled= "true"     android:exported= "false" Android:name= "Com.services.sev.PlayService" >            <intent-filter>                <action android:name= "Com.example.codetest_1.action.startPlayService"/ >            </intent-filter></service>


Note The string for this name

You can add a field to the service class

public static final String ACTION = "Com.example.codetest_1.action.startPlayService";

This allows you to start/Shut down the service by simply modifying the intent call method.

Intent Intent = new Intent ();        Intent.setaction (playservice.action);        This.startservice (Intent);


Intent Intent = new Intent ();        Intent.setaction (playservice.action);        This.stopservice (Intent);



Android development use action to start/close service

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.