Android studio, kotlin 사용
결과화면
MainActivity.kt
package com.example.staticfragment
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
class MainActivity : AppCompatActivity() {
var TAG: String = "MyTest"
var LOG_TAG = "*** Activity ***"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
Log.d(LOG_TAG, "MainActivity: onCreate() called")
}
override fun onRestart() {
super.onRestart()
Log.d(LOG_TAG, "MainActivity: onRestart() called")
}
override fun onStart() {
super.onStart()
Log.d(LOG_TAG, "MainActivity: onStart() called")
}
override fun onResume() {
super.onResume()
Log.d(LOG_TAG, "MainActivity: onResume() called")
}
override fun onPause() {
super.onPause()
Log.d(LOG_TAG, "MainActivity: onPause() called")
}
override fun onStop() {
super.onStop()
Log.d(LOG_TAG, "MainActivity: onStop() called")
}
override fun onDestroy() {
super.onDestroy()
Log.d(LOG_TAG, "MainActivity: onDestroy() called")
}
}
LifecycleFragment.kt
package com.example.staticfragment
import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
class LifecycleFragment : Fragment() {
var LOG_TAG = "$$$ Fragment $$$"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Log.d(LOG_TAG, "LifecycleFragment: onCreate() called")
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
Log.d(LOG_TAG, "LifecycleFragment: onCreateView() called")
return inflater.inflate(R.layout.fragment_lifecycle, container, false)
}
override fun onStart() {
Log.d(LOG_TAG, "LifecycleFragment: onStart() called")
super.onStart()
}
override fun onResume() {
Log.d(LOG_TAG, "LifecycleFragment: onResume() called")
super.onResume()
}
override fun onPause() {
Log.d(LOG_TAG, "LifecycleFragment: onPause() called")
super.onPause()
}
override fun onStop() {
Log.d(LOG_TAG, "LifecycleFragment: onStop() called")
super.onStop()
}
override fun onDestroy() {
Log.d(LOG_TAG, "LifecycleFragment: onDestroy() called")
super.onDestroy()
}
override fun onDestroyView() {
Log.d(LOG_TAG, "LifecycleFragment: onDestroyView() called")
super.onDestroyView()
}
}
onCreate 함수 안에
inflater.inflate(R.layout.fragment_lifecycle, container, false)
이 코드 중요함!
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragmentContainerView"
android:name="com.example.staticfragment.LifecycleFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="197dp"
android:layout_marginTop="308dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
fragment_lifecycle.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
tools:context=".LifecycleFragment">
<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/hello_blank_fragment" />
</FrameLayout>
오늘은 static한 방법 공부함. 내일은 dynamic 공부할 예정.
'수업' 카테고리의 다른 글
웹프로그래밍 - 3-3 시멘틱 태그 (0) | 2023.04.03 |
---|---|
모바일프로그래밍 - lifeCycle (Dynamic Fragment) (0) | 2023.03.28 |
모바일프로그래밍 - LifeCycle (0) | 2023.03.27 |
모바일프로그래밍 - Android 앱 개발 기초 / mile을 km로 변환하는 앱 (0) | 2023.03.27 |
컴퓨터그래픽스 - 5. OpenGL 개요, 구성 요소, freegult 설치 (0) | 2023.03.27 |