简体   繁体   English

如果VPN应用程序被杀死,会发生什么?

[英]What happens to the VPN app if it gets killed?

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. 这是一个普遍的问题,因为我对以下情况没有足够的了解,但不幸的是,在Google上找不到任何可以解释它的东西。

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. 假设我有一个扩展VPN服务的应用程序,一些异步任务,一些线程来读取和处理从VPN接口读取的数据包。 It's understood that once we start the VPN, although we kill the app from the tasks (force-quit), VPN continues to run. 据了解,一旦启动VPN,尽管我们从任务中终止了该应用程序(强制退出),但VPN仍将继续运行。

So what happens when we kill the app? 那么,当我们终止该应用程序时会发生什么? Do all the resources (threads, main UI thread) get destroyed? 是否所有资源(线程,主UI线程)都被破坏了?

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? 完整的UI线程是否会重新初始化?

What is the solution to this kind of scenario with VPN service. VPN服务针对这种情况的解决方案是什么?

It's understood that once we start the VPN, although we kill the app from the tasks (force-quit), VPN continues to run. 据了解,一旦启动VPN,尽管我们从任务中终止了该应用程序(强制退出),但VPN仍将继续运行。

Wrong, "Force Close" destroys the entire app and all the effects along with it such as VPN service no matter what. 错误的是,“强制关闭”会破坏整个应用程序及其所有影响,例如VPN服务,无论如何。 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 对于后台线程,应将它们全部放入AndroidManifest.xml中具有单独进程名称的Service

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. 但是,如果您的应用被手动杀死,那么无论什么事情都将被销毁,并且您对此无能为力,这是Android中的一项安全策略。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM