Closed Mohammed711 closed 3 years ago
I answered this question before with another github account, but I deleted the answer because the account is for only my company account. So I deleted answer and now I answer again with my personal account. The answer is same with before.
I experienced same problem and the difference of codelab is onCreate() method in MainActivity...and I found the problem and fixed it. There are two onCreate(), and I overrided another onCreate().
Override this. override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) }
not this. override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) { super.onCreate(savedInstanceState, persistentState) }
@hong-studio I'm curious about this, why are there two onCreate()? Are they different functions?
The two onCreate() methods should be the same with different parameters, so you could use either one.
As for setting title, you can call this within the activity: https://developer.android.com/reference/android/app/Activity#setTitle(java.lang.CharSequence)
Or change the app name in the strings.xml file.
If you have any issues, feel free to reopen.
override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) { super.onCreate(savedInstanceState, persistentState) }
I noticed that when using the above onCreate() , the up button won't show up. Can someone explain the reason behind this? However, the up button shows if we use the below onCreate().
override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) }
URL of codelab https://developer.android.com/codelabs/basic-android-kotlin-training-shared-viewmodel?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-kotlin-unit-3-pathway-4%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-training-shared-viewmodel#2
In which task and step of the codelab can this issue be found? -Shared ViewModel Across Model
Describe the problem I am not able to change the title of the app bar
Steps to reproduce?
Versions Android Studio version: 4.2.1 API version of the emulator: 30_x86
Additional information Include screenshots if they would be useful in clarifying the problem.