开发者

How can I set an intent's class from a string value?

开发者 https://www.devze.com 2023-01-02 21:18 出处:网络
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.

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 inte开发者_运维技巧nt=new intent();
intent.setClass(this, target);

Thanks


Intent class has the method setClassName

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


You can try to use the forName method of the Class class.

Anyway, I've been wondering the use of the setClassName method... it could be useful in your case maybe

0

精彩评论

暂无评论...
验证码 换一张
取 消