Day54 of #100DaysOfCode
Hii folks 🙌
Today I will be continuing the same pathway in which I will build the Dessert Clicker app.
Unit 3: Navigation
Pathway 1: Navigate between screens
Source: https://developer.android.com/courses/android-basics-kotlin/course
Stages of the activity lifecycle
We will start by downloading the repo from the given link in the course and setting it up in Android Studio.
- Now we will examine the
OnCreate()
method in the app and will add logging:
override fun onCreate(savedInstanceState: Bundle?) {
...
}
The onCreate()
lifecycle method is called once, just after the activity is initialized (when the new Activity
object is created in memory). After onCreate()
executes, the activity is considered created.
Now in the onCreate()
method, just after the call to super.onCreate()
, we will add the following line:
Log.d("MainActivity", "onCreate Called")
Now we will import the log
class
import android.util.Log
Now we will implement the onStart()
method
The onStart()
lifecycle method is called just after onCreate()
.After onStart()
runs, the activity becomes visible on the screen.
override fun onStart() {
super.onStart()
Log.d(TAG, "onStart Called")
}
Then we will move to add more log statements
override fun onResume() {
super.onResume()
Log.d(TAG, "onResume Called")
}
override fun onPause() {
super.onPause()
Log.d(TAG, "onPause Called")
}
override fun onStop() {
super.onStop()
Log.d(TAG, "onStop Called")
}
override fun onDestroy() {
super.onDestroy()
Log.d(TAG, "onDestroy Called")
}
override fun onRestart() {
super.onRestart()
Log.d(TAG, "onRestart Called")
}
Now we will try several use cases:
- Use case 1: Opening and closing the activity
- Use case 2: Navigating away from and back to the activity
- Use case 3: Partially hide the activity
Today I Learned:
- Activity Lifecycle
- Logging with log
- Preserving activity state
- Configuration changes
That is all for Day54 ✅
Thanks for reading, See you tomorrow!
If you are reading my #100Days Journey, feel free to drop by ;)
https://www.mongodb.com/community/forums/t/the-journey-of-100daysofcode-im-kushagra/147693/