Preference跳转activity出错Unable to find explicit activity class
生活随笔
收集整理的这篇文章主要介绍了
Preference跳转activity出错Unable to find explicit activity class
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
使用Preference可以非常方便的实现类似设置页面这样的菜单布局,甚至可以不需写java代码。那么可以在Preference中直接添加页面跳转么?其实非常简单,在Preference添加intent标签即可,如下
<Preferenceandroid:key="offlinemap"android:title="离线地图"android:summary="wifi下载,节省流量"><intentandroid:targetPackage="com.hcz.xxx"android:targetClass="com.hcz.xxxx.ProfileActivity"/> </Preference>但是运行时发现一直报错
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.hcz.xxx/com.hcz.xxxx.ProfileActivity}; have you declared this activity in your AndroidManifest.xml?
但是明明已经在AndroidManifest中注册过了
后来发现targetPackage设置有误,这个必须是build.gradle中的applicationId
因为我的AndroidManifest中的package和build.gradle中的applicationId不同,而targetPackage设置的是AndroidManifest中的package
所以一直报错,修改后即可
总结
以上是生活随笔为你收集整理的Preference跳转activity出错Unable to find explicit activity class的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 使用SearchView报错java.l
- 下一篇: IntentService详解