main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:text="Main" />

</LinearLayout>
sub.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:text="Sub" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:orientation="horizontal">
    </LinearLayout>

</LinearLayout>
manifast.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.gusfree.lifecycle"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="8" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".LifeCycleActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="SubActivity"></activity>
    </application>

</manifest>

LifeCycleActivity.java

package com.gusfree.lifecycle;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;

public class LifeCycleActivity extends Activity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Log.i ("onCreate","onCreateMAIN");
		setContentView(R.layout.main);
		findViewById(R.id.button1).setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View arg0){
				startActivity(new Intent(
						getApplicationContext(),SubActivity.class));					
			}        			
		});       
	}

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

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

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

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

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

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

SubActivity.java

package com.gusfree.lifecycle;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;

public class SubActivity extends Activity{

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.sub);
		findViewById(R.id.button1).setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View arg0) {
				finish(); 			
			}
		});  
	}


	@Override
	protected void onStart() {
		Log.w ("onStart","onStartSUB");
		super.onStart();
	}

	@Override  
	protected void onResume() {
		Log.w ("onResume","onResumeSUB");
		super.onResume();
	}

	@Override
	protected void onPause() {
		Log.w ("onPause","onPauseSUB");
		super.onPause();
	}

	@Override
	protected void onStop() {
		Log.w ("onStop","onStopSUB");
		super.onStop();
	}

	@Override
	protected void onDestroy() {
		Log.w ("onDestroy","onDestroySUB");
		super.onDestroy();
	}

	@Override
	protected void onRestart() {
		Log.w ("onRestart","onRestartSUB");
		super.onRestart();
	}
}


LogCat을 보세요~~


'Android > 2012.04월 강좌' 카테고리의 다른 글

10일차 Alarm  (0) 2012.05.09
9일차 ViewFlipper  (0) 2012.05.08
9일차 SQLite 연동하기(naver 메모장)  (0) 2012.05.08
9일차 복습  (0) 2012.05.08
8일차 Google Map 2  (0) 2012.05.07

+ Recent posts