2

When I call the startActivity() method to start other activity on the onCreate() method;

Did the other lifecircle method execute,like onStart() or onResume()

I had a test

    AppMain.java

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.app_main);

            Log.i(TAG, "onCreate");
            startActivity(new Intent(AppMain.this,AppOther.class));
        }


        @Override
        protected void onRestart() {
            Log.i(TAG, "onRestart");
            super.onRestart();
        }

        @Override
        protected void onStart() {
            Log.i(TAG, "onStart");
            super.onStart();
        }

        @Override
        protected void onRestoreInstanceState(Bundle savedInstanceState) {
            Log.i(TAG, "onRestoreInstanceState");
            super.onRestoreInstanceState(savedInstanceState);
        }

        @Override
        protected void onResume() {
            Log.i(TAG, "onResume");
            super.onResume();
        }


        @Override
        protected void onPause() {
            Log.i(TAG, "onPause");
            super.onPause();
        }

        @Override
        protected void onSaveInstanceState(Bundle outState) {
            Log.i(TAG, "onSaveInstanceState");
            super.onSaveInstanceState(outState);
        }

        @Override
        protected void onStop() {
            Log.i(TAG, "onStop");
            super.onStop();
        }



        @Override
        protected void onDestroy() {
            Log.i(TAG, "onDestroy");
            super.onDestroy();
        }


        @Override
        public void onConfigurationChanged(Configuration newConfig) {
            Log.i(TAG, "onConfigurationChanged");
            super.onConfigurationChanged(newConfig);
        }

    AppOther.java

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.app_other);

        Log.i(TAG, "onCreate");

    }

    @Override
    protected void onRestart() {
        Log.i(TAG, "onRestart");
        super.onRestart();
    }

    @Override
    protected void onStart() {
        Log.i(TAG, "onStart");
        super.onStart();
    }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        Log.i(TAG, "onRestoreInstanceState");
        super.onRestoreInstanceState(savedInstanceState);
    }

    @Override
    protected void onResume() {
        Log.i(TAG, "onResume");

        super.onResume();
    }


    @Override
    protected void onPause() {
        Log.i(TAG, "onPause");

        super.onPause();
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        Log.i(TAG, "onSaveInstanceState");
        super.onSaveInstanceState(outState);
    }

    @Override
    protected void onStop() {
        Log.i(TAG, "onStop");
        super.onStop();
    }



    @Override
    protected void onDestroy() {
        Log.i(TAG, "onDestroy");
        super.onDestroy();
    }


    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        Log.i(TAG, "onConfigurationChanged");
        super.onConfigurationChanged(newConfig);
    }

Logcat:

05-29 05:28:11.583: I/AppMain(1257): onCreate
05-29 05:28:11.614: I/AppMain(1257): onStart
05-29 05:28:11.614: I/AppMain(1257): onResume
05-29 05:28:11.643: I/AppMain(1257): onSaveInstanceState
05-29 05:28:11.643: I/AppMain(1257): onPause
05-29 05:28:11.793: I/AppOther(1257): onCreate
05-29 05:28:11.793: I/AppOther(1257): onStart
05-29 05:28:11.793: I/AppOther(1257): onResume
05-29 05:28:12.383: I/AppMain(1257): onStop

I don't know why the onStart() and onResume() method can still execute; It's seems that startActivity() did not break the AppMain's lifecycle

Grumoon
  • 39
  • 1
  • 3
  • 1
    1. Try to read your question before you post it. 2. sounds like you want to check something simple - add a debug printing to logcat from both methods and see if any of them gets called. – Nir Alfasi May 29 '14 at 03:44
  • Your question is ver ambiguous. – Chefes May 29 '14 at 04:02

2 Answers2

3

Language is pale, speak in code. Just test it.

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Log.v(this.getClass().toString(),"onCreate");
    //start other Activity
    this.startActivity(new Intent(this,OtherActivity.class));
}

@Override
protected void onDestroy() {
    super.onDestroy();
    Log.v(this.getClass().toString(),"onDestroy");
}

@Override
protected void onPause() {
    super.onPause();
    Log.v(this.getClass().toString(),"onPause");
}

@Override
protected void onResume() {
    super.onResume();
    Log.v(this.getClass().toString(),"onResume");
}

@Override
protected void onStart() {
    super.onStart();
    Log.v(this.getClass().toString(),"onStart");
}

}

And the logcat shows: enter image description here

zhenghuiyan
  • 324
  • 4
  • 10
0

Question's way too narrow but if you start another activity, the current activity will toggle onPause(). and if you finished the called activity the previous activity will toggle onResume(). In short it will not call onResume() and onStart() of current activity if you start another acitivity.

JayR
  • 441
  • 1
  • 4
  • 16