Skip to content

Instantly share code, notes, and snippets.

@easternHong
Created November 19, 2014 13:06
Show Gist options
  • Save easternHong/878a1f0851cca663e821 to your computer and use it in GitHub Desktop.
Save easternHong/878a1f0851cca663e821 to your computer and use it in GitHub Desktop.
startActivitySafely
void startActivitySafely(Intent intent) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
Toast.makeText(this, R.string.activity_not_found,
Toast.LENGTH_SHORT).show();
} catch (SecurityException e) {
Toast.makeText(this, R.string.activity_not_found,
Toast.LENGTH_SHORT).show();
e(LOG_TAG,
"Launcher does not have the permission to launch "
+ intent
+ ". Make sure to create a MAIN intent-filter for the corresponding activity "
+ "or use the exported attribute for this activity.",e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment