fix: crash if the built application cannot be launched (closes #759)

This commit is contained in:
Akash Yadav
2023-01-28 22:54:52 +05:30
parent 96ca54c394
commit dadaf0d509
2 changed files with 15 additions and 3 deletions
@@ -192,13 +192,12 @@ abstract class BaseEditorActivity :
if (packageName != null) {
Snackbar.make(binding.realContainer, string.msg_action_open_application, Snackbar.LENGTH_LONG)
.setAction(string.yes) {
val launchIntent = packageManager.getLaunchIntentForPackage(packageName)
launchIntent?.let { startActivity(it) }
tryLaunchApp(packageName)
}
.show()
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@@ -407,6 +406,18 @@ abstract class BaseEditorActivity :
viewModel.statusText = text
viewModel.statusGravity = gravity
}
private fun tryLaunchApp(packageName: String) {
val launchIntent = packageManager.getLaunchIntentForPackage(packageName)
launchIntent?.let {
try {
startActivity(it)
} catch (e: Throwable) {
flashError(string.msg_app_launch_failed)
log.error("Failed to launch application with package name '$packageName'", e)
}
}
}
private fun checkIsDestroying() {
if (!isDestroying && isFinishing) {
@@ -536,4 +536,5 @@
<string name="idepref_general_materialYou">Material You</string>
<string name="idepref_general_materialYou_summary">Enjoy an experience closer to your device (requires restart).</string>
<string name="idepref_general_projectConfig">Project configuration</string>
<string name="msg_app_launch_failed">Failed to launch application. See IDE logs for more info.</string>
</resources>