Android app start-up development

Source: Internet
Author: User

(1) First add permission to start up permissions

<!--boot permissions--    <uses-permission android:name= "Android.permission.RECEIVE_BOOT_COMPLETED"/>

(2) Register a broadcastreceiver to detect the start-up broadcast when the Android system is powered on

Package Com.wxyz.dengchaoqun.testswf;import Android.content.broadcastreceiver;import Android.content.Context; Import android.content.intent;/** * Created by Deng Chao on 2017/2/4. *///boot from start broadcast accept public class Autostartbroadcastreceiver extends Broadcastreceiver {    static final String action_boot = " Android.intent.action.BOOT_COMPLETED ";    @Override public    void OnReceive (context context, Intent Intent) {        if (intent.getaction (). Equals (Action_boot)) {            Intent sayhellointent=new Intent (context,mainactivity.class);            Sayhellointent.addflags (intent.flag_activity_new_task);            Context.startactivity (sayhellointent);}}}    

The emphasis here is that the boot can start the app activity can also start the service, which depends on the specific needs of the app, I am here to start the mainactivity

(3) Registering the service in the configuration file

<!--booting from the broadcast accept        -<receiver android:name= ". Autostartbroadcastreceiver ">            <intent-filter>                <action android:name=" Android.intent.action.BOOT_COMPLETED "/>                <category android:name=" Android.intent.category.HOME "/>            </intent-filter>        </receiver>

  



Android app start-up development

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.