如何将意图中的变量用作目标活动?
String var1 = et.getText().toString();
Intent intent = new Intent(MainActivity.this,MainActivity2.class);//MainActivity2.class => var1
答案 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();
}