Created
November 19, 2014 13:06
-
-
Save easternHong/878a1f0851cca663e821 to your computer and use it in GitHub Desktop.
startActivitySafely
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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