What happens to the VPN app if it gets killed?

755 Views Asked by At

This is a general question as I don't have enough understanding of the following scenario and unfortunately couldn't find anything on google that explains it.

Let's say I have an app that extends VPN Service, some async tasks, some threads to read and handle the packets being read from the VPN interface. It's understood that once we start the VPN, although we kill the app from the tasks (force-quit), VPN continues to run.

So what happens when we kill the app? Do all the resources (threads, main UI thread) get destroyed?

Similarly, when we restart the app, do all the resources get initialized again?

Can you please explain how it works here.

I have this question because I have a background thread that runs on the main thread. When I force close the app, the thread is not interrupted, but when I try to update the thread after restarting the app (after force quit or killing) I get a null pointer exception as that thread is not accessible. Does the complete UI thread gets reinitialized?

What is the solution to this kind of scenario with VPN service.

1

There are 1 best solutions below

0
On

It's understood that once we start the VPN, although we kill the app from the tasks (force-quit), VPN continues to run.

Wrong, "Force Close" destroys the entire app and all the effects along with it such as VPN service no matter what. So the user killing the app manually is the absolute end of everything. dead end. can't do anything about it.

Similarly, when we restart the app, do all the resources get initialized again?

Everything starts over in this situation. even caches might get corrupted and removed.

For background threads you should put them all in a Service that has a separate process name in the AndroidManifest.xml

This way your service will continue to work even if the user clears the Applications history.

But if your app gets killed manually, everything will be destroyed no matter what and you can't do anything about it, this is a security policy in Android.