我怎样才能打开使用名称作为意图通过字符串的活动? [英] How can I open an Activity using the name as string via intent?

查看:123
本文介绍了我怎样才能打开使用名称作为意图通过字符串的活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用String变量containig活动的名字,我想通过故意打开相应的活动。
例如:

I want to use String variable containig the name of an activity, and i want to open the activity via in intent. For example:

next = "foo.class";
Intent baslat = new Intent(this,next);

下一个是我的价值。我想使用的变量是不可能的,因为日食不要让我用两个参数。
我怎样才能解决这个问题?

"next" is my value. I think using variable is impossible because eclipse don't let me use two arguments. How can I solve this problem?

编辑:我试图去让Foo.class

I am trying to go to "foo.class"

编辑:我解决这个问题,你们都不错,pretty:D,对于所有的吻,非常感谢你

I solve the problem, You are all so nice and pretty :D, kisses for all, thank you very much!

推荐答案

OK,使用方法的Class.forName()

String myClass = "foo.class";
Intent myIntent = new Intent(getApplicationContext(), Class.forName(myClass));
startActivity(myIntent );

这篇关于我怎样才能打开使用名称作为意图通过字符串的活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆