TabActivity lifecycle callback in disorder?

59 Views Asked by At

I was thinking that I understand fully the lifecycle of activity until I i have faced an interesting problem today .

I create a tab-type Activity extending from TabActivity as an example of depicting the problem .

I also add log code in the life cycle callback of the activity . here is the details :

protected void onRestart() { 
    super.onRestart();
    MJ_MiscUtils.danielPrintfDebug("MJ_TabMainActivity=>onRestart" , toString() );
} 

protected void onStop() { 
    super.onStop(); 
    MJ_MiscUtils.danielPrintfDebug("MJ_TabMainActivity=>onStop" , toString()  );
} 

protected void onStart() {
    super.onStart(); 
    MJ_MiscUtils.danielPrintfDebug("MJ_TabMainActivity=>onStart", toString()  );
}

public void onCreate(Bundle savedInstanceState) { 
....
    MJ_MiscUtils.danielPrintfDebug("MJ_TabMainActivity=>onCreate" , toString() );       
}

protected void onDestroy() {
    super.onDestroy();
    MJ_MiscUtils.danielPrintfDebug("MJ_TabMainActivity=>onDestroy", toString() ); 
}

Here is the log :

MJ_TabMainActivity=>onCreate com.mujing.distplatform.MJ_TabMainActivity@41c13968 

MJ_TabMainActivity=>onStart com.mujing.distplatform.MJ_TabMainActivity@41c13968 

when I exit from app by pressing the back key, there is no log code of onStop/onDestroy

when I re-launch the app , then the oncreate/onStart is invoked again.

MJ_TabMainActivity=>onCreate com.mujing.distplatform.MJ_TabMainActivity@42385718

MJ_TabMainActivity=>onStart com.mujing.distplatform.MJ_TabMainActivity@42385718 

And , the onStop and ondestroy are invoked immediately after onStart ....But the instance value(41c13968) is not identical to that in onStart(42385718) . That's saying , the older TabMainActivity instance is just destroyed.

MJ_TabMainActivity=>onStop com.mujing.distplatform.MJ_TabMainActivity@41c13968

MJ_TabMainActivity=>onDestroy com.mujing.distplatform.MJ_TabMainActivity@41c13968 

Would you please help to explain if it complies with the official document. if not, then what's the root cause of it?

1

There are 1 best solutions below

0
On BEST ANSWER

Sorry for the delay of providing further details on this scenario. Actually , this disorder is caused by an error in my code. In my project , a service is created to the datapumping . To debug this service , I add some android.os.Debug.waitForDebugger() somewhere. When I unplug the USB and run the application , this issue occurs. When I remove them , the liftcycle callbacks go normally.