是否可以先使用变量创建意图,然后再使用变量启动活动?
示例:标准方法
Intent myIntent = new Intent(Main2Activity.this, Main3Activity.class);
startActivity(myIntent);是否可以使用可变活动;
String newActivity = "Main4.class";
Intent myIntent = new Intent(Main2Activity.this,newActivity);发布于 2016-10-21 02:45:05
如果您可以将活动类名称作为不带.class后缀且具有完整包名字符串,
String newActivity = "org.test.Main4";
那我相信你能做到
try {
Intent myIntent = new Intent(Main2Activity.this, Class.forName(newActivity));
} catch (ClassNotFoundException e) {
e.printStackTrace();
}发布于 2016-10-21 02:47:58
可以使用Class类型来存储特定的类:
Class newActivity = BasicActivity.class;
startActivity(new Intent(this, newActivity));根据您的需要,您可以针对不同的类检查变量。
Class basicActibity = BasicActivity.class;
if (newActivity == basicActibity)https://stackoverflow.com/questions/40161994
复制相似问题