Mar*_*los 38 android android-library android-activity
我有一个Android库项目,我想在另一个Android项目中使用.
该库在其AndroidManifest中声明了一个Activity.当我在第二个项目中尝试以下内容时:
        Intent intent = new Intent(this, ReaderActivity.class);
        startActivity(intent);
我得到以下异常:
 java.lang.RuntimeException: Unable to start activity ComponentInfo{br.com.digitalpages.reader.demo/br.com.digitalpages.reader.demo.ReaderDemoActivity}: android.content.ActivityNotFoundException: Unable to find explicit activity class {br.com.digitalpages.reader.demo/br.com.digitalpages.reader.ReaderActivity}; have you declared this activity in your AndroidManifest.xml?
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
...
 Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {br.com.digitalpages.reader.demo/br.com.digitalpages.reader.ReaderActivity}; have you declared this activity in your AndroidManifest.xml?
     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
...
如何从另一个项目中打开活动?
编辑:根据用户的答案,我将以下行添加到我的第二个项目中
<uses-library android:name="br.com.digitalpages.reader" android:required="true" />
但它仍然不起作用
mah*_*mah 36
我相信你必须在自己的AndroidManifest.xml中包含<activity> - 我认为它不会从库中获取.我没有这方面的参考.
更新:这是官方解决方案.来自doc:
在清单文件中声明库组件
在应用程序项目的清单文件中,必须添加应用程序将从库项目导入的所有组件的声明.例如,您必须声明任何
<activity>,<service>,<receiver>,<provider>,等等,还有<permission>,<uses-library>和相似的元素.声明应在适当的时候通过其完全限定的包名引用库组件.
she*_*tal 20
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
intent.setComponent(new ComponentName("packagename//ex-com.hello", 
                                     "classname//ex-com.hello.ExampleActivity"));
startActivity(intent);
并确保在库中您已声明了活动.您无需在当前项目的清单中声明库活动.
| 归档时间: | 
 | 
| 查看次数: | 43429 次 | 
| 最近记录: |