mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
fix: crash if the built application cannot be launched (closes #759)
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user