호스트 부분
package dev.focusone.multiScreen;
import java.util.Stack;
import android.app.Activity;
import android.os.Bundle;
public class MultiScreenHostActivity extends Activity {
/** Called when the activity is first created. */
// Navigation Stack
protected Stack<MultiScreenActivity> m_MultiActivityStack;
// 현재 액티비티
protected MultiScreenActivity m_TopActivity;
// Not extendable LifeCycle
/* * * * * * * * * * * * * * * * * * * * * * * * */
@Override
final protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
m_MultiActivityStack = new Stack<MultiScreenActivity>();
this.onCreateEX(savedInstanceState);
}
@Override
final protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
if ( m_TopActivity == null)
return ;
m_TopActivity.onStart();
this.onStartEX();
}
@Override
final protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
if ( m_TopActivity == null)
return ;
m_TopActivity.onResume();
this.onResumeEX();
}
@Override
final protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
if ( m_TopActivity == null)
return ;
m_TopActivity.onPause();
this.onPauseEX();
}
final protected void onStop() {
super.onStop();
if ( m_TopActivity == null)
return ;
m_TopActivity.onStop();
this.onStopEX();
}
@Override
final protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
if ( m_TopActivity == null)
return ;
m_TopActivity.onDestroy();
this.onDestroyEX();
}
@Override
final public void onBackPressed() {
// TODO Auto-generated method stub
if ( m_TopActivity == null)
return ;
m_TopActivity.onBackPressed();
this.onBackPressedEX();
}
/**
* 첫번째 Activity를 세팅한다.
* @param activity 새로운 MultiScreenActivity인스턴스.
* @throws Exception
*/
final public void setFirstActivity(MultiScreenActivity activity) throws Exception {
if ( m_MultiActivityStack.size() != 0 )
throw new Exception("Already did setting");
m_MultiActivityStack.push(activity);
m_TopActivity = activity;
m_TopActivity.onCreate(null);
}
// Extendable LifeCycle
/* * * * * * * * * * * * * * * * * * * * * * * * */
protected void onCreateEX(Bundle savedInstanceState) {}
protected void onStartEX() {}
protected void onResumeEX() {}
protected void onPauseEX() {}
protected void onStopEX() {}
protected void onDestroyEX() {}
public void onBackPressedEX() {}
}
스크린 부분
package dev.focusone.multiScreen;
import android.os.Bundle;
import android.view.View;
abstract public class MultiScreenActivity {
// 적용할 화면에 대한 Activity타입이어야한다.
private View m_View;
private boolean isCreated; // 이 액티비티가 한번 만들어졌는지에 대한 체크
private MultiScreenHostActivity m_HostActivity;
public MultiScreenActivity (MultiScreenHostActivity activity) {
m_HostActivity = activity;
}
// Multi Activity LifeCycle
protected void onCreate(Bundle savedInstanceState) {
isCreated = true;
}
protected void onStart(){}
//재호출 할 경우 view를 다시 세팅
protected void onResume() {
m_HostActivity.setContentView(m_View);
}
protected void onPause(){}
protected void onStop(){}
protected void onDestroy(){}
// View Setting Method
public void setContentsView(int resource) {
m_View = View.inflate(m_HostActivity, resource, null);
m_HostActivity.setContentView(m_View);
}
public View findViewById(int id) {
return m_View.findViewById(id);
}
protected MultiScreenHostActivity getHostActivity() {
return m_HostActivity;
}
protected synchronized void startActivity(MultiScreenActivity activity) {
m_HostActivity.m_MultiActivityStack.push(activity);
m_HostActivity.m_TopActivity = activity;
activity.onCreate(null);
activity.onStart();
activity.onResume();
}
protected synchronized void finish() {
MultiScreenActivity popActivity = m_HostActivity.m_MultiActivityStack.pop();
if ( m_HostActivity.m_MultiActivityStack.size() == 0 )
m_HostActivity.finish();
else {
MultiScreenActivity pushActivity = m_HostActivity.m_MultiActivityStack.lastElement();
popActivity.onPause();
popActivity.onStop();
popActivity.onDestroy();
if ( !pushActivity.isCreated ) {
pushActivity.onCreate(null);
pushActivity.onStart();
}
m_HostActivity.m_TopActivity = pushActivity;
pushActivity.onResume();
}
}
protected void onBackPressed() {
finish();
}
}
호스트 상속 클래스
package dev.focusone;
import android.os.Bundle;
import dev.focusone.multiScreen.MultiScreenHostActivity;
public class HostActivity extends MultiScreenHostActivity {
@Override
protected void onCreateEX(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreateEX(savedInstanceState);
try {
setFirstActivity(new FirstScreen(this));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
protected void onStartEX() {
// TODO Auto-generated method stub
super.onStartEX();
}
@Override
protected void onResumeEX() {
// TODO Auto-generated method stub
super.onResumeEX();
}
@Override
protected void onPauseEX() {
// TODO Auto-generated method stub
super.onPauseEX();
}
@Override
protected void onStopEX() {
// TODO Auto-generated method stub
super.onStopEX();
}
@Override
protected void onDestroyEX() {
// TODO Auto-generated method stub
super.onDestroyEX();
}
@Override
public void onBackPressedEX() {
// TODO Auto-generated method stub
super.onBackPressedEX();
}
}
첫번째 화면
package dev.focusone;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import dev.focusone.multiScreen.MultiScreenActivity;
import dev.focusone.multiScreen.MultiScreenHostActivity;
public class FirstScreen extends MultiScreenActivity implements OnClickListener{
private Button m_Button;
public FirstScreen(MultiScreenHostActivity activity) {
super(activity);
// TODO Auto-generated constructor stub
}
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
setContentsView(R.layout.first);
m_Button = (Button) findViewById(R.id.first_button_noName);
m_Button.setOnClickListener(this);
}
@Override
protected void onStart() {
// TODO Auto-generated method stub
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
}
@Override
protected void onStop() {
// TODO Auto-generated method stub
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new SecondScreen(getHostActivity()));
}
}
두번째 화면
package dev.focusone;
import android.os.Bundle;
import dev.focusone.multiScreen.MultiScreenActivity;
import dev.focusone.multiScreen.MultiScreenHostActivity;
public class SecondScreen extends MultiScreenActivity {
public SecondScreen(MultiScreenHostActivity activity) {
super(activity);
// TODO Auto-generated constructor stub
}
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
setContentsView(R.layout.second);
}
@Override
protected void onStart() {
// TODO Auto-generated method stub
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
}
@Override
protected void onStop() {
// TODO Auto-generated method stub
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
}
}
'Android' 카테고리의 다른 글
android activity사이에 검은 line생길 때 (activity 테마설정) && 엑티비티 테마 style코드 (0) | 2012.06.14 |
---|---|
안드로이드 기본 플레이어로 연속 재생기능 만들기 (0) | 2012.01.13 |
암시적 인텐트와 명시적 인텐트 (0) | 2012.01.13 |
외부 어플이랑 연결하기, 암시적 인텐트 ( 외부 메신저, 메일 이용하기 ) (0) | 2012.01.13 |
리스트뷰 해더와 푸터 ( 리스트뷰 첫부분 마지막부분 붙이기 ) (0) | 2012.01.12 |