I´ve an app (APP1) which should open other app (APP2) and wait for the result. I´m doing it this way.
private fun startBridgeActivity(fileName: String, isProduction: Boolean) {
val intent = Intent(Intent.ACTION_MAIN)
when (isProduction) {
true -> {
intent.component = ComponentName(
"com.myapp",
"com.myapp.view.ui.ItemSelectionActivity"
)
}
else -> {
intent.component = ComponentName(
"com.myapp.dev",
"com.myapp.view.ui.ItemSelectionActivity"
)
}
}
try {
startActivityForResult(intent, REQUEST_CODE)
} catch (e: Exception) {
e.printStackTrace()
Toast.makeText(this@MainActivity, "This activity does not exist", Toast.LENGTH_LONG).show()
}
}
Then APP2 receives this intent and opens itself. The launch method on this APP2 it´s just the standard. The navigation inside APP2 is as follows:
ReceiverActivity - Step1Activity - Step2Activity - LastActivity
I´ve tried setting the result and finishing LastActivity, but it doens't work. Also tried with finishAffinity
and finishAndRemoveTasks
but they also didn't work.
Then what I did was calling ReceiverActivity from LastActivity and setting there the result and finishing it. But that leaves me on the homescreen and the result wont get to APP1.
val receiverActivityIntent = Intent(this@LastActivity, ReceiverActivity::class.java)
receiverActivityIntent.putExtra("end", true)
TaskStackBuilder.create(this@ReceiverActivity)
.addParentStack(ReceiverActivity::class.java)
.addNextIntent(receiverActivityIntent)
.startActivities()
finish()
I readed some other SO answers where someone wrote that the Activity from APP1 would be added to the stack of APP2 and that might be why the app goes to the homescreen.
Any help will be appreciated.
Thanks.