问题
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