Closed jetsystemservices closed 3 years ago
It's scope problem of val navController You have to Declare navController outside fun onCreate() but inside of MainActivity class Try
class MainActivity : AppCompatActivity(R.layout.activity_main){
private lateinit var navController: NavController
......
......
......
}
Sorry for my broken English, English is not my first language Hehe
Yup, @Gaebobman is correct, declare navController as a class variable and then you can access it within the onSupportNavigateUp() method.
URL of codelab https://developer.android.com/codelabs/basic-android-kotlin-training-navigation-backstack?authuser=4&continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-kotlin-unit-3-pathway-4%3Fauthuser%3D4%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-training-navigation-backstack#2
In which task and step of the codelab can this issue be found? Step 3.2
Describe the problem
override
fun onSupportNavigateUp(): Boolean { return navController.navigateUp() || super.onSupportNavigateUp() }` navController unresolved referenceSteps to reproduce? 1.Load: https://github.com/google-developer-training/android-basics-kotlin-cupcake-app/tree/viewmodel 2.Import to Android Studio 3.Write the code according to step 3.2
Versions Android Studio version: 4.2.2 API version of the emulator: 19
Additional information Include screenshots if they would be useful in clarifying the problem.