public class MyService extends Service {
public MyService() {
System.out.println("==MyService===========MyService()==========");
}
@Override
public void onCreate() {
super.onCreate();
System.out.println("==MyService========创建==onCreate()==========");
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
System.out.println("==MyService========启动==onStartCommand()==========");
return super.onStartCommand(intent, flags, startId);
}
@Override
public void onDestroy() {
super.onDestroy();
System.out.println("==MyService========销毁==onDestroy()==========");
}
}
--启动、停止
Intent intent = new Intent(MainActivity.this,MyService.class);
startService(intent);
stopService(intent);