之前摘要写过一篇,理论太多,罗里吧嗦,回过头去看,一头雾水
那天又自己查了下。废话不说了。上代码
这个接收器,接收系统启动的事件
package sll.auto.main;
import android.content.broadcastreceiver;
import android.content.context;
import android.content.intent;
public class receive extends broadcastreceiver{
@override
public void onreceive(context context, intent intent) {
// todo auto-generated method stub
intent mboot=new intent(context, autostartactivity.class);
mboot.setflags(intent.flag_activity_new_task);
context.startactivity(mboot);
}
其定义在mainfest.xml中定义了
<receiver android:name="receive">
<intent-filter>
<action android:name="android.intent.action.boot_completed"/>
<category android:name="android.intent.category.home"/>
</intent-filter>
</receiver>
然后写一个空白的启动activity就成(不需要另外与自启动相关的关键代码)
import android.app.activity;
import android.os.bundle;
public class autostartactivity extends activity {
@override
public void oncreate(bundle savedinstancestate) {
super.oncreate(savedinstancestate);
setcontentview(r.layout.main);
}