views:

20

answers:

2

I am trying to set the class for an intent to the address listed in a string value, so that I can launch a given activity. The string is composed dynamically during runtime.

Is there anyway to make something like the code below run:

String target=com.test.activity1.class;
Intent intent=new intent();
intent.setClass(this, target);

Thanks

A: 

You can try to use the forName method of the Class class: http://is.gd/cKCzw Anyway, I've been wondering the use of the setClassName method ( http://is.gd/cKCZY )... it could be useful in your case maybe

Cristian
A: 

Intent class has the method setClassName

Intent intent = new Intent().setClassName(context,target);
Francesco