标签:
BootReceiver.java
package com.hanqi.testbr; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.util.Log; public class BootReceiver extends BroadcastReceiver { public BootReceiver() { Log.e("ATG","构造开机完成广播接收器"); } @Override public void onReceive(Context context, Intent intent) { Log.e("ATG","广播接收器自动启动Service"); //启动服务 context.startService(new Intent(context,BootService.class)); } }
BootService.java
package com.hanqi.testbr; import android.app.Service; import android.content.Intent; import android.os.IBinder; import android.support.annotation.Nullable; import android.util.Log; /** * Created by Administrator on 2016/4/25. */ public class BootService extends Service { @Nullable @Override public IBinder onBind(Intent intent) { return null; } @Override public void onCreate() { super.onCreate(); Log.e("ATG", "服务自动启动的"); } }
标签:
原文地址:http://www.cnblogs.com/cuikang/p/5433693.html