簡體   English   中英

android sdk產品風格 - 當我使用intent開始一個新活動時找不到活動

[英]android sdk product flavors - activity not found when I start a new activity using intent

我有一個工作的應用程序,我添加了2種產品口味。 這個應用程序在第一個屏幕上有一個菜單,允許用戶選擇下一個活動,我用意圖加載。

這是AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name="com.alpha.aloedu.MainActivity"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.alpha.aloedu.guideddrawing.GuidedLetterDrawingActivity"
        android:label="Guided Letter Drawing"
        android:screenOrientation="portrait" />
    <activity
        android:name="com.alpha.aloedu.buildvocabulary.BuildVocabularyActivity"
        android:label="Image Plus Word"
        android:screenOrientation="portrait" />
    <activity
        android:name="com.alpha.aloedu.findthepicture.FindThePictureActivity"
        android:label="Find the Picture"
        android:screenOrientation="portrait" />
    <activity
        android:name="com.alpha.aloedu.findtheletter.FindTheLetterActivity"
        android:label="Find the Letter"
        android:screenOrientation="portrait" />
    <activity
        android:name="com.alpha.aloedu.fillintheletter.FillInTheLetterActivity"
        android:label="Find the Letter"
        android:screenOrientation="portrait" />
    <activity
        android:name="com.alpha.aloedu.EndActivity"
        android:label="End Activity"
        android:screenOrientation="portrait" />

    <activity
        android:name="com.alpha.aloedu.AdminActivity"
        android:label="Admin Activity"
        android:theme="@style/AppTheme.NoActionBar"
        android:screenOrientation="portrait"
        />

</application>

<supports-screens
    android:largeScreens="true"
    android:normalScreens="true"
    android:requiresSmallestWidthDp="480"
    android:resizeable="false"
    android:smallScreens="false"
    android:xlargeScreens="true" />

這是gradle文件的相關部分:

productFlavors {
    de {
        applicationIdSuffix ".de"
        versionName "1.1de"
    }
    fr {
        applicationIdSuffix ".fr"
        versionName "1.1fr"
    }
}

這是源樹:

在此輸入圖像描述

這是我加載下一個活動的代碼:

    Intent intent = new Intent();
    intent.setClassName("com.alpha.aloedu", newClassName);
    currentActivity.startActivity(intent);
    currentActivity.finish();

我在第二行設置了斷點,“newClassName”具有正確的值。 但是,當我運行“deDebug”變體時,我在第三行出錯:

android.content.ActivityNotFoundException:無法找到顯式活動類{com.alpha.aloedu / com.alpha.aloedu.guideddrawing.GuidedLetterDrawingActivity}; 你有沒有在AndroidManifest.xml中聲明這個活動?

GuidedLetterDrawingActivity類確實存在於主源樹中,也存在於AndroidManifest.xml中。

感謝您提供任何幫助。

您必須在其清單文件中聲明每種flavor的活動
... \\ src \\ de \\ AndroidManifest.xml
... \\ src \\ fr \\ AndroidManifest.xml

在清單中聲明每個新活動。 即使您更改名稱,也必須修改清單文件。

     <application
    android:allowBackup="true"
    android:icon="@drawable/icon"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity
        android:name=".new_Activity"
        android:label="@string/app_name"/>

    <activity
        android:name=".new_Activity2"
        android:label="@string/app_name"/>
    </application>

這必須在主java文件中聲明

    Intent intent = new Intent(MainActivity.this, newActivity.class);
        startActivity(intent);

    Intent intent1 = new Intent(MainActivity.this, newActivity2.class);
        startActivity(intent1);

根據您的要求在相同或不同的函數中執行代碼的意圖塊。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM