Java – Getting class by its name

androidclassjava

If I have an Activity class called TestActivity in my application, is there a way to get its class by its name like in this example:

Class<?> c = getClassByName("TestActivity");

Best Solution

use forName instead..

something like this..

 try {
    Class<?> act = Class.forName("com.bla.TestActivity");
 } catch (ClassNotFoundException e) {
        e.printStackTrace();
}