开发者

How to prevent an android activity to get killed

开发者 https://www.devze.com 2023-02-04 11:20 出处:网络
I have developed an application that does require to do constant network activity. ThisActivity does the network connections thru an AsyncTask, sometime this work being done in background (application

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 havin开发者_如何学Cg 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.


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).


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


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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消