繁体   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