Kotlin / anko

Pleasant Android application development
Apache License 2.0
15.88k stars 1.29k forks source link

how to access finish() on DSL #629

Open arjava opened 6 years ago

arjava commented 6 years ago

I use anko layout, in it I love the menu to logout and close, when I try to use finish (), I do not find it and I think there is another way or is it not allowed ?, please your answer

`toolbar { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { inflateMenu(menu_main_menu) }

                onMenuItemClick { item ->
                    when(item?.itemId) {
                        navLogout -> {

                            // get finish() here

                            true
                        }
                        else -> {
                            false
                        }
                    }
                }
            }`
jeiea commented 6 years ago

I can use finish. But it is provided as Activity instance method. Where did you put that code?

hendrawd commented 6 years ago
ui.owner.finish()

Where ui is AnkoContext<YourActivity>