简体   繁体   English

android sdk产品风格 - 当我使用intent开始一个新活动时找不到活动

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

I have a working app to which I have added 2 product flavors. 我有一个工作的应用程序,我添加了2种产品口味。 This app has a menu on the first screen which allows the user to choose the next activity, which I load with an intent. 这个应用程序在第一个屏幕上有一个菜单,允许用户选择下一个活动,我用意图加载。

Here is AndroidManifest.xml: 这是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" />

Here is the relevant portion of the gradle file: 这是gradle文件的相关部分:

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

Here is the source tree: 这是源树:

在此输入图像描述

Here is the code where I load the next activity: 这是我加载下一个活动的代码:

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

I have set a breakpoint on the second line and "newClassName" has the correct value. 我在第二行设置了断点,“newClassName”具有正确的值。 However, when I run the "deDebug" variant, I get an error on the third line: 但是,当我运行“deDebug”变体时,我在第三行出错:

android.content.ActivityNotFoundException: Unable to find explicit activity class {com.alpha.aloedu/com.alpha.aloedu.guideddrawing.GuidedLetterDrawingActivity}; android.content.ActivityNotFoundException:无法找到显式活动类{com.alpha.aloedu / com.alpha.aloedu.guideddrawing.GuidedLetterDrawingActivity}; have you declared this activity in your AndroidManifest.xml? 你有没有在AndroidManifest.xml中声明这个活动?

The class GuidedLetterDrawingActivity does exist in the main source tree, and also in AndroidManifest.xml. GuidedLetterDrawingActivity类确实存在于主源树中,也存在于AndroidManifest.xml中。

Thank you for any help you can provide. 感谢您提供任何帮助。

You must declare activities of each flavor in its manifest file 您必须在其清单文件中声明每种flavor的活动
...\\src\\ de \\AndroidManifest.xml ... \\ src \\ de \\ AndroidManifest.xml
...\\src\\ fr \\AndroidManifest.xml ... \\ src \\ fr \\ AndroidManifest.xml

Declare each new activity in manifest. 在清单中声明每个新活动。 Even if you change the name you have to modify the manifest file. 即使您更改名称,也必须修改清单文件。

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

This has to be declared in main java file 这必须在主java文件中声明

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

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

execute the intent block of code as per your requirement in the same or different functions. 根据您的要求在相同或不同的函数中执行代码的意图块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM