Service - startService()
AndroidManifest.xml
<service android:name=".MyService" > <intent-filter> <action android:name="com.bob.servicetest" /> </intent-filter> </service>
Activity
startService(new Intent("com.bob.servicetest")); stopService(new Intent("com.bob.servicetest"));
MyService.class
public class MyService extends Service { public static final String TAG = "MyService"; @Override public void onCreate() { super.onCreate(); Log.i(TAG, "onCreate"); } @Override public IBinder onBind(Intent arg0) { Log.i(TAG, "onBind"); return null; } @Override public int onStartCommand(Intent intent, int flags, int startId) { Log.i(TAG, "onStartCommand"); return super.onStartCommand(intent, flags, startId); } @Override public void onDestroy() { super.onDestroy(); Log.i(TAG, "onDestroy"); } }