Thursday, May 10, 2012

AndroidDev: How to start a specific Activity

Hi developer!
In this article I will show you how to start a specific Activity by specific name or package.
For this, I used Explicit Intent and Extras.
An Explicit Intent is an intent that specify the class to load.
By the PackageManager I have retrieved Intent for a specific package:

 Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.package.address");

Then I put some extras within:

 
LaunchIntent.putExtra("isdebug", true);
startActivity(LaunchIntent);


A specific use of this app is to create an Intent within particular Extras to pass to your activity for determinate specific feature in yuor application.
For example if you want to run your app with "debug features" you can pass a boolean into the Extras so in your app you can manage this choice.
Another specific use is to create an application that can launch other app or "app launcher".
Amazing!!