简体   繁体   中英

Android multi app: how to create two apps within one project?

I have one almost completed Java application with authentication and need to add to this project another one app to reuse auth code, for example.

As I heard there could be some kind of two "main activities" with different icons to launch them separately. Also I cannot check this info, because don't know how this named and any tries before leads me in other way.

So the question is how to register those activities in Manifest and how to configure run menu? Or if I'm wrong - what else ways exists which could fit for my requiremrnts?

Thanks.

You should consider using flavors for your apps. This allows you setting different app name, icons, code for each flavor.

Here is an example for defining two flavors in your main module's build.gradle:

buildTypes {
        debug{...}
        release{...}
    }
    // Specifies one flavor dimension.
    flavorDimensions "main"

productFlavors {
        demo {
            // Assigns this product flavor to the "main" flavor dimension.
            // If you are using only one dimension, this property is optional,
            // and the plugin automatically assigns all the module's flavors to
            // that dimension.
            dimension "main"
            applicationId "com.appdemo"
            versionNameSuffix "-demo"
        }
        full {
            dimension "main"
            applicationId "com.appfull"
            versionNameSuffix "-full"
        }
    }

You can then set the resources of each app (images, code, strings...) by overriding the default files in each flavor's subdirectory ie yourmodule/demo/ and yourmodule/full/

Basically need to create two entrance points using activities and add icons inside them.

So left this here just in case.

    <activity android:name=".MainActivity_1"
        android:icon="@mipmap/icon_1">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

    <activity android:name=".MainActivity_2"
        android:icon="@mipmap/icon_2">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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