Android developers start of the boot

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.lidaochen.test001">
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <receiver android:name=".BootReceiver">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED"></action>
            </intent-filter>
        </receiver>
    </application>

</manifest>
Package com.lidaochen.test001; 

Import android.app.ProgressDialog;
 Import android.content.DialogInterface;
 Import android.os.SystemClock;
 Import android.support.v7.app.AlertDialog;
 Import android.support.v7.app.AppCompatActivity;
 Import android.os.Bundle;
 Import android.util.Log;
 Import android.view.View;
 Import android.widget.Toast; 

public  class the MainActivity the extends AppCompatActivity {
     // following method is to shut off the back key program 
    @Override
     public  void  onBackPressed () {
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}
Package Penalty for com.lidaochen.test001; 

Import android.content.BroadcastReceiver;
 Import android.content.Context;
 Import android.content.Intent;
 Import android.util.Log; 

public  class BootReceiver the extends BroadcastReceiver {
     // When the phone is restarted when the call 
    @override
     public  void the onReceive (the context context, the Intent Intent) { 
        Log.e ( "Boot", "come!" );
         // open Activity in this method inside 
        the Intent intent1 = new new the Intent (context, the MainActivity. class );
         / /Note that the broadcast receiver can not be directly turned inside Activity, tasks need to add a tag stack, 
        intent1.setFlags (Intent.FLAG_ACTIVITY_NEW_TASK);
         // open the Activity 
        Context.startActivity (intent1); 
    } 
}

 

Guess you like

Origin www.cnblogs.com/duxie/p/11032702.html