如何使用变量设置目标活动

时间:2014-11-15 22:48:12

标签: java android variables android-intent

如何将意图中的变量用作目标活动?

String var1 = et.getText().toString();
Intent intent = new Intent(MainActivity.this,MainActivity2.class);//MainActivity2.class => var1

1 个答案:

答案 0 :(得分:0)

以下是:

try {
    // Considering var1 = MainActivity2
    Class cls = Class.forName("package.name." + var1);
    Intent intent = new Intent(MainActivity.this, cls);
    startActivity(intent);
} catch (ClassNotFoundException e) {
    e.printStackTrace();
}