1. onStart() ,onStartCommand() instead.As Follows :
-------------------------------------------------onStart()
public void onStart(Intent intent, int startId) {
}--------------------------------------------------
onStartCommand: public int onStartCommand(Intent intent, int flags, int startId) {
onStart(intent, startId);
return mStartCompatibility ? START_STICKY_COMPATIBILITY : START_STICKY;
}--------------------------------------------------
Google APIvoid onStart(Intent intent, int startId)
This method is deprecated. Implement onStartCommand(Intent, int, int) instead.
onStart方式已经过时,被onStartCommand取代 int onStartCommand(Intent intent, int flags, int startId)
Called by the system every time a client explicitly starts the service by calling startService(Intent),
providing the arguments it supplied and a unique integer token representing the start request.-------------------------------------------------
那么为何还会在onStartCommand中 调用onStart()方法?---------------------------------------------------
他的启动顺序是 onCreate() ---> onStartCommand() ---> onStart() ,说明他却是调用了onStart()
注释掉 onStartCommand()后, 依然可以启动Service啊 !! onCreate() ---> onStart()
观2.2源码中中 onStartCommand依然调用了onStart方法啊
既然都能正确的调用 那么onStart() 为何不推荐使用呢 ?
-------------------------------------------------onStart()
public void onStart(Intent intent, int startId) {
}--------------------------------------------------
onStartCommand: public int onStartCommand(Intent intent, int flags, int startId) {
onStart(intent, startId);
return mStartCompatibility ? START_STICKY_COMPATIBILITY : START_STICKY;
}--------------------------------------------------
Google APIvoid onStart(Intent intent, int startId)
This method is deprecated. Implement onStartCommand(Intent, int, int) instead.
onStart方式已经过时,被onStartCommand取代 int onStartCommand(Intent intent, int flags, int startId)
Called by the system every time a client explicitly starts the service by calling startService(Intent),
providing the arguments it supplied and a unique integer token representing the start request.-------------------------------------------------
那么为何还会在onStartCommand中 调用onStart()方法?---------------------------------------------------
他的启动顺序是 onCreate() ---> onStartCommand() ---> onStart() ,说明他却是调用了onStart()
注释掉 onStartCommand()后, 依然可以启动Service啊 !! onCreate() ---> onStart()
观2.2源码中中 onStartCommand依然调用了onStart方法啊
既然都能正确的调用 那么onStart() 为何不推荐使用呢 ?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货