1.要做的就是监听系统发出的broadcast
public class FlorenceText extends BroadcastReceiver{
public void onReceive(Context context, Intent intent) {
if(Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())){
start(context);
}
}
}
2.在
AndroidMenifest.xml里还要将receiver加上, 并写明程序的入口就是FlorenceTest
<application
Android:icon="@drawable/ic_launcher"
Android:label="@string/app_name" >
<receiver
Android:name=".main.FlorenceTest"
Android:exported="true"
Android:process=":remote">
<intent-filter >
<action
Android:name="
Android.intent.action.BOOT_COMPLETED" />
<category
Android:name="
Android.intent.category.HOME"/>
</intent-filter>
</receiver>
</application>
这样,程序就可以在开机时自动运行了