How can I start a new android activity using class name in a string?

Here is a code by which you can start activity using the name of the activity

String activityToStart = "com.example.MainActivity";
try {
    Class<?> c = Class.forName(activityToStart);
    Intent intent = new Intent(this, c);
    startActivity(intent);
} catch (ClassNotFoundException ignored) {
}

EDIT

Here class name will be full name of the class with the package name. For example if your package name will be x.y.z and if you have Activity name called A then the full name of the Activity A will be x.y.z.A.


An even better way (and one that is used in the system to launch Browser.apk along with other apps that aren't bundled with AOSP):

Intent intent = new Intent();
intent.setClassName("com.android.browser","com.android.BrowserActivity");

context.startActivity(intent);

Alternatively, if you want to check that you can start the Activity from the command line, you can do something like this from your shell:

adb shell
am start com.android.browser/.BrowserActivity