How to prevent an android activity to get killed

我是研究僧i 提交于 2019-12-18 09:37:33

问题


I have developed an application that does require to do constant network activity. This Activity does the network connections thru an AsyncTask, sometime this work being done in background (application not having focus). My application sometimes gets killed after 30 mins, even if the system does not seem to lack resources (memory).

I have read the Activity life cycle in the Application Fundamentals section on developer.android.com, but can't find an answer. What would be the proper way to programmatically prevent my Activty to get killed.

Thank you.


回答1:


If you use a Service and make sure it stays active (by first starting it and simply not stopping it) the application wont be killed (unless it's extremely low on memory of course).




回答2:


You should use a service instead of using an Activity to do work in the background.




回答3:


Does your application have to be an activity? Can it utilize a background service?

http://developer.android.com/reference/android/app/Service.html#ServiceLifecycle



来源:https://stackoverflow.com/questions/4685269/how-to-prevent-an-android-activity-to-get-killed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!