Problem statement: I want to launch an application which contains a set of services [run in the background]. These services will be communicating to a client activity [which also is a part of the application]. When the application is killed (manually by swiping out the running application OR through Settings->Apps->Running application->stop the application), I want the services to be running in the background. When the application is launched back, it will resume the communication with the services running in the background.
Solution:
For the communication between the services and the client activity, I have put all the background services in a separate process and the activity in the application process. The services and the activity communicate through the Messenger (the IPC provided by android). This works fine, without any issue.
The problem I am having is with the services to be run in the background when the application which launched the services is killed manually.
Killing manually implies: manually by swiping out the running application OR through Settings->Apps->Running application->stop the application.
For this I tried the following
The set of services are running as a global process (by using android:process in the Manifest). But these services are killed when the application is killed.
I include 2 activities in the Manifest file and both have following lines in the Manifest
"android.intent.action.MAIN" and "android.intent.category.LAUNCHER" for both the activities.
Here out of the 2 activities, one activity and all the services are made a part of one process. The other activity (which is the client activity that uses the services) is made a part of the application. Basically thinking that 2 applications will be launched and one of the application (which holds all the services) will be running irrespective of the other being killed. However I see that only one application will be running and when I kill it, all the services are made to stop.
So I think that the only way I could possibly achieve this is, if I am able to launch 2 Virtual Machines from a single apk. So that all the services are part of one VM and the client activity(that uses the services) is part of the other VM. Now if the application holding the client activity is killed, the VM holding the services will be running without any issue.
But is there is a way that one apk can allow for launching 2 applications which run on 2 different VMs. If yes, how can I do that?
OR
Is there any other solution to my problem statement.
Thanks in advance.