191210 TIL

1 minute read

기본적 안드로이드 구성

AndroidManifest.xml: fundamental characteristics of the app and defines each of its components MyActivity.java: start the activity and loading the layout file Activity_my.xml: activit를 위한 레이아웃, 보통 한 화면 = 한 액티비티로 구성 Build.gradle: configure how the gradle tools compile and build your app

Intent

Intent : an object providing runtime binding between separate components (such as two activities) 인텐트는 다른 액티비티를 실행하는데 사용된다. 하나의 화면에 모든 기능을 담기 어렵기 때문에, 페이지 전환과 페이지간 데이터 전달할 때 사용됨.

startActivity(intent) // 액티비티 띄우기 액티비티 추가시, manifest에도 해당 액티비티 추가해주어야 한다! logical parent일 경우에도 해당 사항을 manifest에 추가해야 한다.

SubActivity에서도 인텐트를 받아 데이터를 출력하기 때문에 여기서도 상위 액티비티 처럼 인텐트를 선언해줘야 한다.

<meta data
android:name =="android.support.PARENT_
android:value ==".My Activity"/> 

Intentintent =newIntent(this,DisplayMessageActivity.class); // 처럼 바인딩 하면 된다.

Fragment

wrap_content: content에 딱 맞는 최소 사이즈의 뷰 match_parent: parent 크기만큼의 뷰

Fragment를 사용하는 이유:

  • combine multiple fragments in a single activity to build a multi-pane UI
  • can reuse a fragment in multiple activities
  • can support dynamic and flexible UI on large screens.

Fragment의 특징:

  • has its own lifecycle
  • receives its own input events
  • can be added or removed while the activity is running
// 예시
transaction.addBackStack(null) // addbackstack을 사용하여 화면을 stack 에 저장한다. back 누르면 스택에 저장된 프래그먼트 사라짐
transaction.commit() // 변경 내용이 적용되기 위해서 

Toast Message

사용자에게 간단한 메세지를 띄울 수 있는 기능

import android.widget.Toast

Life cycle

(https://developer.android.com/reference/android/app/Activity.html?hl=ko)

  • onCreate(): Activity가 처음 만들어질 때 호출된다. 어플이 실행될 때 가장 먼저 실행된다.
  • onStart(): Activity가 멈췄다면, 그 다음에 호출된다.
  • onResume(): Activity가 사용자에게 보여지려고 할 때 호출된다.
  • onRestart(): Activity가 멈췄다(Stopped)가 다시 호출된다.

  • onPause(): Activity 위에 다른 Activity가 올라와서 focus를 잃었을 때 호출된다.
  • onStop(): Activity 위에 다른 Activity가 올라와 화면에서 완전히 가려질 때 호출된다.
  • onDestroy(): Activity가 스택에서 완전하게 사라져야할 때 호출된다.

Shared Preferences

간단하게 저장할 것이 있을 때 사용하는 API다. 저장될 key-value의 값이 많지 않을 때 사용된다.

SQLite

간단한 데이터베이스를 이용하고 저장하고 싶을 때 사용한다. SQLiteOpenHelper를 사용한다.

-

모바일 프로그래밍 기말고사를 준비하며 간단하게 정리해봤습니다..

Categories:

Updated: