-2

below is two method of the IntentService source

@Override
public void onStart(Intent intent, int startId) {
    Message msg = mServiceHandler.obtainMessage();
    msg.arg1 = startId;
    msg.obj = intent;
    mServiceHandler.sendMessage(msg);
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    onStart(intent, startId);
    return mRedelivery ? START_REDELIVER_INTENT : START_NOT_STICKY;
}

when i start the subclass of intentservice with the debug mode, i found that,it call the onstart method first and then do the onStartCommand method,but in the onStartCommand method,it do not call "onStart(intent, startId);"

as i saw the source,i think that is should be first call onStartCommond method and then do the onStart method in the onStartCommond method, as the result show above,i confuse that ,some one help me ?thanks

lgw150
  • 170
  • 1
  • 3
  • 13

1 Answers1

0

as i read this document,i wrote a new class called "MyService" which extends Service,and Override the onStart method and onStartCommand method,show below:

@Override
public void onStart(Intent intent, int startId) {
    Log.e(TAG,"onStart");
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.e(TAG,"onStartCommand");
    Toast.makeText(this, "service starting", Toast.LENGTH_SHORT).show();
    ........
}

after i start MyService,it just call the onStartCommand method,but the onStart method is never be called! so,i think that,because i debug the android source in the sdk,not the source in my project ,so the debug is not correct as run.but i still refuse the source in IntentService.java,the onStartCommand method still call the onStart(intent, startId);

if you have some advice,please tell me! thanks !

lgw150
  • 170
  • 1
  • 3
  • 13