android - deptno/deptno.github.io GitHub Wiki
- 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 - ๊ฐ๋ก ๋ชจ๋์์ ์ฌ์ฉ