从 PreferenceScreen
开始 Activity 的正确方法是什么? ?
这是我的代码,它不起作用。
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<Preference android:title="Change password">
<intent
android:targetClass="org.kekem.activity.MyActivity"
android:targetPackage="org.kekem.activity"/>
</Preference>
</PreferenceScreen>
Activity 也在我的 list 文件中声明如下:
<activity
android:name=".activity.MyActivity"
android:label="Change password"
android:parentActivityName=".activity.MainActivity"
android:screenOrientation="portrait">
</activity>
抛出这个错误:
android.content.ActivityNotFoundException: Unable to find explicit activity
class org.kekem.activity/org.kekem.activity.MyActivity have you declared
this activity in your AndroidManifest.xml?
最佳答案
targetPackage
您的 <intent>
上的属性标记应该是您的应用程序的包 ID(也称为应用程序 ID),而不是您的 Activity 所在的 Java 包的名称。
因此您的 <intent>
可能应该是这样的,假设您的应用程序 ID 是 org.kekem
:
<intent
android:targetClass="org.kekem.activity.MyActivity"
android:targetPackage="org.kekem"/>
关于android - 从偏好 Activity 启动 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41363988/