Android中<Preference>跳轉Activity報錯ActivityNotFoundException

<Preference
            android:title="退出登錄"
            android:summary="注銷當前賬號">
            <intent
                android:action="android.intent.action.VIEW"
                android:targetPackage="com.dragonlayout.iHealth"
                android:targetClass="com.dragonlayout.iHealth.ui.setting.LogoutDialogActivity"/>
</Preference>

Preference是按照上面的寫的,下面的是AndroidManifest.xml的代碼:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.dragonlayout.iHealth">
    <application
        android:name=".iHealthApp"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <activity
            android:name=".ui.setting.LogoutDialogActivity"
            android:theme="@style/LogoutDialog" />

    </application>
</manifest>

運行之后一直報錯:

android.content.ActivityNotFoundException: Unable to find explicit activity class {com.dragonlayout.iHealth/com.dragonlayout.iHealth.ui.setting.LogoutDialogActivity}; have you declared this activity in your AndroidManifest.xml?

網上查找了好多方法,但是我在AndroidManifest.xml明明已經注冊過了Activity,而且程序的包名寫的都對。

因為我之前改過工程的名字,還有包的名字,我覺得可能是這個原因導致的,后來在AndroidManifest.xml的Merged Manifest面板看了一下,發現package節點還是修改之前的工程名,于是去build.gradle(Module.app)下面看了一下,發現果然applicationId還是修改之前的工程名,這下問題就找到了。

修改之后運行成功!

友情提醒,改工程名和包名的時候,先百度一下,看看正確的修改方法是什么,別自己瞎幾把改

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容