We used the nice alex2k8 solution for a while, until we found that it does not work on all devices on the released version downloaded from Google Play ,
Unfortunately, the system was not:
- throw any exception
- write down the reason for the error
We used the following method to solve the problem:
protected void startMainActivityWithWorkaround() throws NameNotFoundException, ActivityNotFoundException { final String packageName = getPackageName(); final Intent launchIntent = getPackageManager().getLaunchIntentForPackage(packageName); if (launchIntent == null) { Log.e(LOG_TAG, "Launch intent is null"); } else { final String mainActivity = launchIntent.getComponent().getClassName(); Log.d(LOG_TAG, String.format("Open activity with package name %s / class name %s", packageName, mainActivity)); final Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.setComponent(new ComponentName(packageName, mainActivity));
source share