Im currently working on an app, that has a BottomSheet as a menu. The objective of this menu is to start intents depending on the item selected. I tried starting an Intent like below, however Android Studio says:
None of the following functions can be called with the arguments supplied.
(Context!, Class<*>!) defined in android.content.Intent
(String!, Uri!) defined in android.content.Intent
What am i doing wrong? Is there a better way to start an Intent from a class?
frgBottomSheetDrawer.kt
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
super.onCreateView(inflater, container, savedInstanceState)
navDrawer.setNavigationItemSelectedListener { menuItem ->
when (menuItem!!.itemId) {
R.id.ndListFolder -> Intent(this, ndActFolder::class.java).also {
startActivity(it)
}
R.id.ndListSettings -> Intent(this, ndActSettings::class.java).also {
startActivity(it)
}
true
}
}
return inflater.inflate(R.layout.fragment_bottomsheet, container, false)
}
I found a clean solution.
We can write a cleaner Intent line:
this.startActivity(Intent(activity, actAbout::class.java))
In case you need the activity normally, we can write:
new intent = Intent(activity, actAbout::class.java))
startActivity(intent)