본문 바로가기
Activity

[예제] Activity Life Cycle

by 하드락 2022. 10. 2.

[예제] Activity Life Cycle

< main.xml >

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <Button
        android:id="@+id/Button01"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Activity Life Cycle"/>

</LinearLayout>

 

< HelloTestActivity.java >

package com.hardrock.hellotest;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class HelloTestActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        final Button button = (Button) findViewById(R.id.Button01);

        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Intent intent = new Intent(Intent.ACTION_VIEW,
                    Uri.parse("http://www.google.com"));
                startActivity(intent);
            }
        });
        Log.i("MY_TAG", "OnCreate()");
    }

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

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

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

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

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

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

}

 

< AndroidManifest.xml >

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.hardrock.hellotest"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".HelloTestActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

    <uses-permission android:name="android.permission.INTERNET"/>

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

</manifest>

 

'Activity' 카테고리의 다른 글

액티비티 (Activity)  (0) 2022.10.02

댓글