我想测试应用程序中是否存在名为" test“的活动。可能在调用startActivity之前或在其catch块中使用清单文件执行以下操作:
Starting an Activity with Intent and SetClassName
所以说:
if(test.exists){
Activity is registered and start it
}
else{
create Activity and add it in manifset programmatically, as this would be a dynamic Activity
}发布于 2012-04-12 19:58:19
我们不能以编程方式在manifeast文件中添加活动,即使您从JSON响应中获得它。
如果你正在启动原生活动,我们通常根本不会将它们添加到manifeast文件中,但对于某些事情,我们需要添加权限才能在我们的应用程序中使用它们。
发布于 2012-04-12 20:15:50
使用forName代替..
像这样的东西..
try {
Class<?> act = Class.forName("TestActivity");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
// do what you wish if not exist
}发布于 2012-04-12 20:22:04
清单和其他存在于apk中的xmls不能被modified.So,你可能不得不重用你的组件,你可以为此使用片段(如果我正确理解你的需求的话)。或者简单地重用一个活动,
检查活动的存在很容易完成。
https://stackoverflow.com/questions/10122470
复制相似问题