-
Notifications
You must be signed in to change notification settings - Fork 0
android
deptno edited this page Jun 9, 2023
·
11 revisions
- Actions -> New Module
- Settings -> Editor -> General -> Auto import -> Kotlin
- Add unambiguous imports on to fly
- Optimize imports on the fly (for current project)
- 아래서 위로 스와이프 -> 시스템
- Auto Rotate
- System Language -> 테스트할 언어 첫번째로
- LinearLayout
- RelativeLayout
- FrameLayout
- GridLayout
- ConstraintLayout
- as-is
overridefunonCreate(savedlnstanceState: Bundle?) {
super.onCreate(savedlnstanceState)
setContentView(R.layout.main_activity)
findViewById(R.id.text1)
}- to-be
findViewById 사용을 피하기 위해서 gradle 에서
viewBinding설정이 사용된다.
android {
viewBinding {
enabled true
}
}overridefunonCreate(savedlnstanceState: Bundle?) {
super.onCreate(savedlnstanceState)
val binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
}- Single Abstract Method(SAM) - 오브젝트 대신 메소드를 할당하여 처리한다.
override fun onCreate(savedlnstanceState: Bundle?) {
super.onCreate(savedlnstanceState)
val binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
binding.startButton.setOnClickListener {
// 이벤트 처리
}
}
- 액티비티 시작
- onCreate call setContentView
- onStart
- onResume
- 액티비티 실행(setContentView 에서 지정한 UI)
- onPause 포커스가 없는상태, 화면 분할 등 -> onResume
- onStop 비활성화 상태, 홈 버튼을 눌러서 나간 상태 등-> onRestart -> onStart
- onDestroy -> onCreate
- 액티비티 종료 @todo restart 등 추가 필요
onResume -> onPause -> onStop -> onSaveInstanceState -> onDestroy -> onCreate -> onStart -> onRestoreInstanceState -> onResume
인텐트를 통해 시스템에 액티비티의 생성을 요청한다.
val intent = Intent(this, MainActivity::class.java)
intent.putExtra("key", "value")
startActivity(intent)
startActivityForResult(intent, intrequestCode)생성 후 받는 쪽에서는 getIntent 를 통해서 인텐트를 얻고 인자를 가져올 수 있다.
인텐트 실행시에 특정 앱을 지정하고싶다면 패키지를 설정한다.
intent.setPackage("com.google.android.apps.maps")실행한 쪽에서 에러가 난다.
There was a problem communicating with Google servers.
앱의 내부에서는 명시적으로 클래스를 지정해서 실행, 암시적으로도 가능하나 권장된다. 암시적으로는 실행할 수 없는 경우도 존재한다.
val intent = Intent(this, MainActivity::class.java)외부에서 액티비티를 실행할 수 있도록 manifest 파일에 intent 설정을 해줘야한다.
<activity android:name=".oneActivity" />
<activity android:name=".TwoActivity">
<intent-filter>
<actlon android:name="ACTION EDIT" />
</intent-filter>
</activity>
<service ... />
<receiver ... />데이터 전달
- - android:name 은 유일하지 않아도된다. 기능을 보여주는 이름을 사용하자. eg, android.intent.action.MAIN
- - android:name -> android.intent.category.LAUNCHER
- - 필요한 데이
런처앱은
android.intent.category.LAUNCHER카테고리의action.intent.action.MAIN을 가져와서 리스트업하는 액티비티다.
- https://developer.android.com/guide/topics/resources/providing-resources?hl=ko 해당 리스트를 통해 리소스 디렉토리에 suffix 를 붙임으로써 특정 상황에서 사용되는 리소스 임을 명시한다. 언어, 디바이스 방향 상태, 해상도 등이 포함된다. 중복 명시도 가능한데 순서가 존재한다.
- res/layout/activity_main.xml - 세로 모드에서 사용
- res/layout/
land/activity_main.xml - 가로 모드에서 사용