1.一个activity、一个BroadcastReceiver、一个service.
2.在Manifest上添加几行代码。 一盆不显示应用图标、自启动服务的小应用就做好了。MainActivity
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); this.startService(new Intent(this, TestService.class)); }Service
public void onCreate() { super.onCreate(); Toast.makeText(getApplicationContext(), "xhm", Toast.LENGTH_LONG).show(); } @Override public IBinder onBind(Intent intent) { Toast.makeText(getApplicationContext(), "不xhm", Toast.LENGTH_LONG).show(); return null; }Service
@Override public void onReceive(Context arg0, Intent arg1) { // TODO Auto-generated method stub Intent mBootIntent = new Intent(arg0, TestService.class); arg0.startService(mBootIntent); }最后不要忘了配置Manifest.xml
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <service android:name=".TestService" android:label="@string/app_name"> </service> <receiver android:name=".BootReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver> <activity android:name=".MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> <data android:host=".MainActivity" android:scheme="com.xhm.hideiconxhm"/> </intent-filter> </activity>源码下载
