How to open another application from current application on Android? – Different Approach

Posted Posted by Ercan in Android, BLOG     Comments No comments
Sep
13

Opening  an application from your own application is simple and you can find the solution everywhere like this :

Intent i = new Intent(Intent.ACTION_MAIN);
i.setComponent(new ComponentName("app package name", "app launch activity's classname"));
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);

The problem here is that if you do not know the application’s launch activity’s classname, you can not open the application. Of course one can say that: “I can access this file from Package Manager – Application Info”. My answer will be : “Try and see :)”. ApplicationInfo sometimes returns null values which makes the developer crazy.

Here is my approach to this situation (getLaunchIntentForPackage) :

Intent i = new Intent(Intent.ACTION_MAIN);
PackageManager manager = getPackageManager();
i = manager.getLaunchIntentForPackage("app package name");
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);

Hope this also will help to you!

Post comment

Spam Protection by WP-SpamFree