Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Application Files in one Android app

I made three apps, which I now want to ship in one apk file (one installation). On startup of the "wrapper app" the user should decide which app to run.

So far, so good, but the problem is, each app is using global constants from an Application file. Is there a way to build the three apps into one, where each app uses its own application file?

Thanks!

To avoid confusion i add a short example:

App 1:

public class AApplication extends Application {
    public static String CONSTANT_1 = "aaa";
}

App 2:

public class BApplication extends Application {
public static String CONSTANT_1 = "bbb";
}

App 3:

public class CApplication extends Application {
    public static String CONSTANT_1 = "ccc";
}
like image 518
Elias Avatar asked May 28 '26 13:05

Elias


1 Answers

Ok, since the idea I head is obviously not realizable I came up with the following workaround:

  1. I created an Apllication class in the new Project

    public class NewApplication extends OldSuperApplication {}
    
  2. I added a method

    public static void setApplication(RGCApplication a) {
        CONSTANT_1 = a.CONSTANT_1;
        ...
    } 
    
  3. after selecting the desired "sub-app" on the startscreen in this case application "A" i call

    NewApplication.setApplication(new AApplication());
    

    or

    NewApplication.setApplication(new BApplication());
    

I'm not sure if this is smelly coding or not, but it works!

like image 140
Elias Avatar answered May 31 '26 05:05

Elias