[07-D2][UI 설계] Activity, LogCat Debug

[01] Activity의 이해
     - 하나의 윈도우 화면에 해당, 클래스로 대응됨.
     - Activity Class 및 ListActivity같은 확장 기능을 제공하는 클래스를 상속받아 구현.
     - onCreate() 메소드에서 setContentView()메소드를 이용해 사용자 인터페이스 출력.
     - intent filter등을 통해 Activity의 추가 기능을 지정 가능.


1. Activity Lifecycle
   - Reference에서 API 참조.

 


2. Activity Stack
   - 액티비티가 실행되면 스택의 자료구조와 같은 형태로 액티비티를 관리함.

     새로운 액티비티 -----> 활성 액티비티
                             :
                             :
                            뒤로가기 버튼 클릭 및 종료 기능작동
                             :
                             :
                             :
                            바로전 활성 액티비티
                            기타 액티비티 3
                            기타 액티비티 2
                            기타 액티비티 1 <--- 메모리 부족시 자동 종료.

 


3. Activit State
   1) 활성 Activity: Stack의 맨위에 있으며 사용자의 포커스를 받고 있음.
   2) 일지 중지 Pause: 사용자에게 보이나 포커스를 받고 있지 않은 상태, 투명 액티비티등의 실행의 경우.
   3) 중지 Stopped: 액티비티가 화면에서 보이지 않을 경우.
   4) 비활성 Inactive: 액티비티 스택에서 제거됨.

 

 


[02] LogCat Debug
     - 로깅 기능을 통하여 개발시에 진행 상황을 체크할 수 있다.
1. 로깅 메서드
   - Log.e(): 에러를 기록.
   - Log.w(): 경고를 기록.
   - Log.i(): 처리상황등 정보성 메시지를 기록.
   - Log.d(): 개발시 에러 처리를 위해 에러 수정 목적으로 기록.
   - Log.v(): 상세 정보를 기록.

 


2. 사용 방법
   import android.util.Log;
   .....
   .....
   private static final String Log_TAG = "TableLayoutTest";
   .....
   .....
   // LogCat View에 출력
   System.out.println("str의 값: " + str);
   Log.d(Log_TAG, str);

 


3. AndroidManifest.xml 파일 설정
   아래처럼'android:debuggable="true"'추가 할 것.

   <application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">

 


4. 실행시 Debug As...로 실행해야 로그를 볼 수 있다.

 

 

5. 프로젝트 생성
   - Project Type: Android Project
     Project name: Debugging_4
     Application name: Debugging_4
     Package name: android.debugging
     Create Activity(Activity name): Debugging
     Min SDK Version: 4


1) styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="main">
        <item name="android:textSize">16sp</item>
    </style>
    <style name="standard" parent="main">
        <item name="android:textColor">#FFFFFF</item>
    </style>
    <style name="title" parent="main">
        <item name="android:textColor">#00FF00</item>
    </style>
    <style name="btn_1" parent="@android:style/Widget.Button">
        <item name="android:textColor">#000000</item>
        <item name="android:textSize">16sp</item>
        <item name="android:gravity">center_vertical|center_horizontal</item>
    </style>
</resources>

 


2) strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Hello World, Debugging!</string>
    <string name="app_name">Debugging_4</string>
</resources>

 


3) 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"
    >
<TextView 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text=" 숫자를 입력하세요...."
    style="@style/main"
    />
<LinearLayout android:id="@+id/LinearLayout01"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content">
    <EditText android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="7"
            android:id="@+id/edtN"
            android:text="@+id/edtN"
            style="@style/main" />
    <Button android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="3"
    android:id="@+id/btnExecute"
    android:text="@+id/btnExecute"
    style="@style/main"  />
</LinearLayout>

<TextView android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/txvResult"
    android:text="@+id/txvResult"
    android:layout_marginTop="10dp"
    style="@style/main"
    />

<Button android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/btnFinish"
    android:text="@+id/btnFinsih"></Button>
</LinearLayout>

 


4) debugging.java
package android.debugging;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class Debugging extends Activity implements OnClickListener{
   
    EditText edtN;
    Button btnExecute;
    TextView txvResult;
    Button btnFinish;
   
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        Log.d("D", "onCreate() execute...");
       
        edtN = (EditText)findViewById(R.id.edtN);
        edtN.setText("");
       
        btnExecute = (Button)findViewById(R.id.btnExecute);
        btnExecute.setOnClickListener(this);
        btnExecute.setText("소인수 분해 실행");
       
        txvResult = (TextView)findViewById(R.id.txvResult);
        txvResult.setText("");
       
        btnFinish = (Button)findViewById(R.id.btnFinish);
        btnFinish.setOnClickListener(this);
        btnFinish.setText("종료");
    }

    public void calculate(){
        int[] s = new int[20];     // 소인수 분해한 수 저장
        String str="";                // 소인수 분해한 결과

        int n = Integer.parseInt(edtN.getText().toString());  // 입력받는 수, 나누어 지는 수
        out_label:
        if (n >= 2){
            int c = 0;   // 소인수 계산처리, 배열 index
            int k = 2;   // 젯수, 나누는수             
            while(true){
                if (n % k != 0){
                    k = k + 1;
                    Log.d("D", "k: "+k);
                }else{
                    c = c + 1;     // 배열 인덱스 증가
                    Log.d("D", "c: "+c);
                    s[c] = k;      // 배열에 값 저장
                    // 새로운 n  
                    // 20 / 2 = 10
                    // 10 / 2 = 5
                    //  5 / 5 = 1
                    n = n / k;   // 나누어 떨어진 경우 1
                    Log.d("D", "n: "+n);
                    if (n != 1){
                        k = 2;
                        continue;
                    }else{
                        if(c == 1){ // 약수가 하나라면
                            str = "1과 자기자신으로만 나누어 떨어지는 소수";
                            break out_label;
                        }else{
                            for(int y=1; y<=c-1; y++){
                                str = str + (s[y] + "X");
                            }
                            str = str  + (s[c]) + " 입니다.";
                            break out_label;
                        }
                    }
                }
            }
        }else{
            str = "소수가 아님";
        }
        Log.d("D", "str: "+str);
        txvResult.setText(str);      
    }
   
    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.btnExecute){
            calculate();   
        }else  if (v.getId() == R.id.btnFinish){
            finish();
        }
       
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.d("D", "onDestroy() execute...");
    }

    @Override
    protected void onPause() {
        super.onPause();
        Log.d("D", "onPause() execute...");
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        Log.d("D", "onRestart() execute...");
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.d("D", "onResume() execute...");
    }

    @Override
    protected void onStart() {
        super.onStart();
        Log.d("D", "onStart() execute...");
    }

    @Override
    protected void onStop() {
        super.onStop();
        Log.d("D", "onStop() execute...");
    }
   
     
   
}

 

 

Posted by ▶파이팅◀

블로그 이미지
Let's start carefully from the beginning
▶파이팅◀

태그목록

공지사항

Yesterday
Today
Total

달력

 « |  » 2024.5
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

최근에 올라온 글

최근에 달린 댓글

글 보관함