Is it possible to get a class name based a string. For example
String activityName = "Activity";
Intent i = new Intent(context, ...);
Some how convert the string to call the activity class like
Intent i = new Intent(context, Activity.class);
Is it possible to get a class name based a string. For example
String activityName = "Activity";
Intent i = new Intent(context, ...);
Some how convert the string to call the activity class like
Intent i = new Intent(context, Activity.class);
This is very possible. First, you will have to use the full name of the activity
instead of the the file name, such as com.package.Activity
.
String className = "com.package.Activity";
Then you can create a Class
using that name like so:
Class<?> myClass = Class.forName(className);
Simply create a new instance of this Class
and cast it to an Activity
.
Activity myActivity = (Activity) myClass.newInstance();
Try like this
String activityName ="com.project.net.Activity";// provide the class name with domain
Intent i= new Intent( context, Class.forName(activityName));
startActivity(i);