IT/Android

android - 액티비티 생명주기

노마드오브 2018. 9. 25. 21:53
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<Button
android:id="@+id/btnDial"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="전화걸기" />
<Button
android:id="@+id/btnFinish"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="끝내기" />

</LinearLayout>


package com.example.it.myapplication8_8;

import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setTitle("액티비티 테스트 예제");
android.util.Log.i("액티비티 테스트", "onCreate()");

Button btnDial = (Button) findViewById(R.id.btnDial);
btnDial.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Uri uri = Uri.parse("tel:010-1234-5678");
Intent intent = new Intent(Intent.ACTION_DIAL, uri);
startActivity(intent);
}
});

Button btnFinish = (Button) findViewById(R.id.btnFinish);
btnFinish.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}

@Override
protected void onDestroy() {
super.onDestroy();
android.util.Log.i("액티비티 테스트", "onDestory()");
}

@Override
protected void onPause() {
super.onPause();
android.util.Log.i("액티비티 테스트", "onPause()");
}

@Override
protected void onRestart() {
super.onRestart();
android.util.Log.i("액티비티 테스트", "onRestart()");
}

@Override
protected void onPostResume() {
super.onPostResume();
android.util.Log.i("액티비티 테스트", "onPostResume()");
}

@Override
protected void onStart() {
super.onStart();
android.util.Log.i("액티비티 테스트", "onStart()");
}

@Override
protected void onStop() {
super.onStop();
android.util.Log.i("액티비티 테스트", "onStop()");
}
}