Search code examples
androidsd-cardandroid-build

Installing different versions of the same apk at runtime


I have the following situation, I have an Android codebase where I read data from a DB on an sdcard. Now Lets say I have two folders mnt/sdcard/folder1 which has 1.sqlite in it and mnt/sdcard/folder2 which has 2.sqlite in it. Is there a way I can build and install two apk's 1.apk and 2.apk which read from the respective folders and databases at runtime? The codebase is the same - just at run time - one of the apk's is called 1.apk which knows it has to read from the first folder and the second from second. And both are installable at the same time.

OR

is there a better way to achieve this ?


Solution

  • I'm not entirely clear on what you're trying to do, but the only way to have two versions of your code running on the same device is to have two different package names for the two .apk files.

    Put your common code base into a library project, then define two application projects, one for each configuration. Make each application project dependent on the common code base and just define the few things you need that are specific to each configuration.

    If you need both applications running at the same time, I think this is the only way to do it. However, if you need an application that can behave selectively one way or the other when it runs, then it sounds like you can just use some run-time flags.

    Alternatively, you can make each data set accessible through a service and dynamically attach to the required service at run time. Whether this makes sense depends on what you're trying to accomplish with all this.

    EDIT Another approach is to have separate launch icons for the two behaviors, each tied to a different activity in your application. See this thread for more info about this approach.