主要有两个类,一个service,一个broadcastReceiver,
service类:
public class TestService extends Service { public void onCreate(){ super.onCreate(); Toast.makeText(getApplicationContext(), "Toast", Toast.LENGTH_LONG).show(); }
broadcastReceiver类:
@Override public void onReceive(Context arg0, Intent arg1) { // TODO Auto-generated method stub Intent mBootIntent = new Intent(arg0, TestService.class); arg0.startService(mBootIntent); }
Manifast:
<receiver android:name=".BootReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
这些都是关键代码。
下载地址:http://download.csdn.net/detail/qq_34698126/9681290
安卓service后台运行,自启动,隐藏安装图标
不想隐藏图标的话请看博文:http://blog.csdn.net/qq_34698126/article/details/53146292