This answer recommends using AndroidManifest’s android:launchMode="singleTask" to limit an activity to a single instance.
That’s great for applications in which all activities are part of the project, but when I have several application using a Library Project in which the application’s main activity is defined, the Library Project’s AndroidManifest is ignored and so I can’t really use that android:launchMode="singleTask" attribute there.
If I use that android:launchMode="singleTask" in the application’s AndroidManifest.xml, then each activity has a different name and this attribute will limit to a single instance only the same application, not different applications using this shared activity (used as a Library Project).
What I really want is that at any given moment, only one application (among the different applications using that shared Library Project’s activity) can run.
Is this doable using the android:launchMode="singleTask" attribute?
If this isn’t possible, what other approach is recommended?
The Library Project is just something you use to re-use code. When the application is compiled, the resulting
.apkfile doesn’t know about the Library Project that helped create it. That said, it shouldn’t be possible to enforce the singleton property (across different.apk‘s) by manipulating the Library Project’sAndroidManifest.xmlfile.You might be able to enforce this behavior by subclassing
Application. You can read more about this here.