From 46c9c4b80e225ae5bd261759a461c06eafdf4f49 Mon Sep 17 00:00:00 2001 From: Fredrik Fornwall Date: Tue, 1 Mar 2016 16:33:22 +0100 Subject: [PATCH] Catch IllegalArgumentException from startActivity --- .../java/com/termux/app/TermuxActivity.java | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/termux/app/TermuxActivity.java b/app/src/main/java/com/termux/app/TermuxActivity.java index e14b7158..f5672f0c 100644 --- a/app/src/main/java/com/termux/app/TermuxActivity.java +++ b/app/src/main/java/com/termux/app/TermuxActivity.java @@ -731,21 +731,23 @@ public final class TermuxActivity extends Activity implements ServiceConnection } return true; } - case CONTEXTMENU_STYLING_ID: { - Intent stylingIntent = new Intent(); - stylingIntent.setClassName("com.termux.styling", "com.termux.styling.TermuxStyleActivity"); - try { - startActivity(stylingIntent); - } catch (ActivityNotFoundException e) { - new AlertDialog.Builder(this).setMessage(R.string.styling_not_installed) - .setPositiveButton(R.string.styling_install, new android.content.DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=com.termux.styling"))); - } - }).setNegativeButton(android.R.string.cancel, null).show(); - } - } + case CONTEXTMENU_STYLING_ID: { + Intent stylingIntent = new Intent(); + stylingIntent.setClassName("com.termux.styling", "com.termux.styling.TermuxStyleActivity"); + try { + startActivity(stylingIntent); + } catch (ActivityNotFoundException | IllegalArgumentException e) { + // The startActivity() call is not documented to throw IllegalArgumentException. + // However, crash reporting shows that it sometimes does, so catch it here. + new AlertDialog.Builder(this).setMessage(R.string.styling_not_installed) + .setPositiveButton(R.string.styling_install, new android.content.DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=com.termux.styling"))); + } + }).setNegativeButton(android.R.string.cancel, null).show(); + } + } return true; case CONTEXTMENU_TOGGLE_FULLSCREEN_ID: toggleImmersive();