Android Start-up service

Source: Internet
Author: User

1  PackageCom.example.lenovo.guangbo;2 3 ImportAndroid.app.Service;4 Importandroid.content.Intent;5 ImportAndroid.os.IBinder;6 ImportAndroid.util.Log;7 8  Public classMyServiceextendsService {9      PublicMyService () {TenLOG.E ("TAG", "Boot Successful"); One     } A  - @Override -      Publicibinder onbind (Intent Intent) { the         //Todo:return The communication channel to the service. -         Throw NewUnsupportedoperationexception ("not yet implemented"); -     } - } +  -MyService
1  PackageCom.example.lenovo.guangbo;2 3 ImportAndroid.content.BroadcastReceiver;4 ImportAndroid.content.Context;5 Importandroid.content.Intent;6 ImportAndroid.util.Log;7 8  Public classKaijiqdextendsBroadcastreceiver {9      PublicKAIJIQD () {Ten     } One  A @Override -      Public voidOnReceive (Context context, Intent Intent) { -  theLOG.E ("TAG", "Receive boot complete broadcast"); -         //Start the service -Context.startservice (NewIntent (Context,myreceiver.class)); -     } + } -  +Kaijiqd.java
1<Service2Android:name= ". MyService "3Android:enabled= "true"4Android:exported= "true"/>5 6<receiver7Android:name= ". KAIJIQD "8Android:enabled= "true"9Android:exported= "true" >Ten<intent-filter> One<action android:name= "Android.intent.action.BOOT_COMPLETED" > A  -</action> -</intent-filter> the</receiver> -  -Androidmanifest
<uses-permission android:name= "Android.permission.RECEIVE_BOOT_COMPLETED" ></uses-permission>

Android Start-up service

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.