본문 바로가기

개발자/Android

안드로이드개발 호출순서 OnCreate, Onstart, OnResume, OnPause, OnStop, OnDestroy

반응형

안드로이드개발 호출순서, 수명주기 값 저장하기


package com.example.han.h0122;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

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

Toast.makeText(getApplicationContext(),"onCreate() Call.",Toast.LENGTH_LONG).show();
}

@Override
protected void onStop() {
Toast.makeText(getApplicationContext(),"onStop() Call.",Toast.LENGTH_LONG).show();
super.onStop();
}

@Override
protected void onDestroy() {
Toast.makeText(getApplicationContext(),"onDestroy() Call.",Toast.LENGTH_LONG).show();

super.onDestroy();
}

@Override
protected void onPause() {
Toast.makeText(getApplicationContext(),"onPause() Call.",Toast.LENGTH_LONG).show();

super.onPause();
}

@Override
protected void onResume() {
Toast.makeText(getApplicationContext(),"onResume() Call.",Toast.LENGTH_LONG).show();

super.onResume();
}

@Override
protected void onStart() {
Toast.makeText(getApplicationContext(),"onStart() Call.",Toast.LENGTH_LONG).show();

super.onStart();
}
}

다음과 같은 Override를 통해 어떤 메소드가 순서대로 호출되는지 확인해 봅시다.

어플을 실행시키게 되면

가장먼저 OnCreate() -> OnStart(), 인터넷연결을 위한 OnResum()이 실행 됩니다.


그리고, 뒤로가기버튼을 누르게 되면 OnPause() -> OnStop() -> OnDestroy() 순서로 진행됩니다.


반응형