Android에서, 화면은 Activity단위로 움직인다.

특정 Context에서 또다른 Activity를 실행시키고, 현재의 Activity를 종료 시키는 방법에 대해서 알아 보려고 한다. 

Context Class를 찾아 보면 startActivity라는 녀석이 있다. Context Class에 정의 되어 있기 때문에, Context의 SubClass인, Activity는 물론 Service Object에서도 특정 Activity를 실행 시킬 수 있다. 

public abstract void startActivity (Intent intent)

Since: API Level 1

Launch a new activity. You will not receive any information about when the activity exits.

Note that if this method is being called from outside of an Activity Context, then the Intent must include the FLAG_ACTIVITY_NEW_TASK launch flag. This is because, without being started from an existing Activity, there is no existing task in which to place the new activity and thus it needs to be placed in its own separate task.

This method throws ActivityNotFoundException if there was no Activity found to run the given Intent.

Parameters
intentThe description of the activity to start.
Throws
ActivityNotFoundException

startActivity()를 통해서, activity를 실행시키게 되면, 현재의 Activity 는 Pause상태에 접어 들게 된다. 

특정 Activity()를 종료 시키기 위해서는 Activity Class내의 finishXXX() Method들을 사용하면 된다. 
가장 기초적인것만 살펴보면, finish()가 있다. 

public void finish ()

Since: API Level 1

Call this when your activity is done and should be closed. The ActivityResult is propagated back to whoever launched you via onActivityResult().


finish() 가 호출되면, 현재 Activity가 Destroy 상태가 되며, (OnDestroy() 호출됨 )  이전 Activity 가 다시 Active상태가 된다 ( onResume() 호출됨 )

이런식으로 대강 Activity의 흐름이 흘러간다. 

나중에 finishActivity(Intent, int ) 와 같은 함수들이 쓸일이 생기면 그때 걔네들을 좀 살펴봐야 겠다.



+ Recent posts