简体   繁体   English

如何更改 android studio 中启动模块的默认值?

[英]How change default on launch module in android studio?

I have two modules in my android studio project.我的 android 工作室项目中有两个模块。 One module displays "Hello World" on screen, and the other module displays "Hello Module" on screen.一个模块在屏幕上显示“Hello World”,另一个模块在屏幕上显示“Hello Module”。 How to decide, which module to run when the app launches.如何决定在应用程序启动时运行哪个模块。 Apparently "Hello Module" is getting displayed on screen.显然“Hello Module”正在屏幕上显示。 How to use the other module by default on launch of the app.如何在启动应用程序时默认使用其他模块。

Before the apk is generated, all the manifests in your project are combined in a process called as manifest-merging .在生成 apk 之前,您项目中的所有清单都会在一个称为manifest-merging的过程中 合并 So you should be able to change launcher activity by moving the following intent-filter from your old launcher activity to the new launcher activity:因此,您应该能够通过将以下意图过滤器从旧启动器活动移动到新启动器活动来更改启动器活动:

<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

Since Veneet Reddy has given the correct idea about your problem, I'm about to give you this solution in the manifest file do it like this :由于 Veneet Reddy 已经就您的问题给出了正确的想法,我将在清单文件中为您提供此解决方案,请执行以下操作:

<activity android:name=".YourDesiredActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

This is the way to do this.这是做到这一点的方法。 However the Manifest file will be seen in the android studio in your left window pane and do remember to choose the Android option from above the menu See the image you'll get a better idea.但是 Manifest 文件将在您左侧窗格的 android studio 中看到,请记住从菜单上方选择Android 选项查看图像您会得到一个更好的主意。

Android 清单文件图片

Happy Learning!快乐学习!

Every module has a build.gradle file inside.每个模块内部都有一个build.gradle文件。 The module which has apply plugin: 'com.android.application' in it's corresponding build.gradle file is supposed to be the base module of the application.具有apply plugin: 'com.android.application'在其对应的build.gradle文件中的模块应该是应用程序的基础模块。

A module can have more than one activity.一个模块可以有多个活动。 The AndroidManifest.xml file inside the base module should have it's activities in there.基本模块中的AndroidManifest.xml文件应该有它的活动。 The activity we need to run on app starting has to contain the following codes inside the opening and closing tags of the activity.我们需要在应用程序启动时运行的活动必须在活动的开始和结束标记中包含以下代码。

<intent-filter>
 <action android:name="android.intent.action.MAIN" />
 <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

Got this error trying to add Jetpack Compose to my existing project.尝试将 Jetpack Compose 添加到我的现有项目时出现此错误。

After following the official doc steps , in my case, it was an error in another module I am using in my project;在按照官方文档步骤进行操作后,就我而言,这是我在项目中使用的另一个模块中的错误; there were no errors in app module.应用程序模块中没有错误。

Android Studio error was completely misleading (like many other times). Android Studio 错误完全是误导性的(就像很多其他时候一样)。 The best thing to do in these situations is to run gradle in the terminal:在这些情况下最好的办法是在终端中运行 gradle:

./gradlew assembleDebug

This gave me a specific and error log that I could finally fix.这给了我一个特定的错误日志,我终于可以修复了。 Hope it helps someone else.希望它能帮助别人。

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

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