I have an activity A, where I launch another activity through intent. But my objective is to pass the keys down to activity1, instead of handling at activity2. Returning false from onkeydown or onkeyup is no use. How can I achieve this?
Class activity1: Activity(){
Override oncreate(){
// set view
// launch activity2
launchactivy2()
}
fun launchactivy2(){
val playIntent = Intent("android.intent.action.VIEW")
playIntent.putExtra("position", "top")
playIntent.component = ComponentName(
"com.myapp.package”,
"com.myapp.package.activity2”
)
context.startActivity(playIntent)
}
fun onKeyDown(){
// Handle keys here
}
}
my activity2 looks like below, where I'm not handling keys, but retuning false.
Class activity2: Activity(){
Override oncreate(){
// set view
}
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
super.onKeyDown(keyCode, event)
return false
}
override fun onKeyUp(keyCode: Int, event: KeyEvent?): Boolean {
super.onKeyUp(keyCode, event)
return false
}
}
Tried only returning false, instead of super call from onKey.. methods and of no use. Is it possible to achieve this?
Is it possible to achieve this?
No. Each activity is its own window; key events go to a window.
The simplest solution is to have a single activity, rather than two.