ArrayList becomes null
I have written a service and get xml from web server and after that i put it in my ArrayList. The problem i am facing is that i have bind my service to AlarmManager and it executes it after every one minute, and the arraylist gets null ever开发者_如何学编程y time the service is called. I want to retain is previous values but unable to find any solution.
The somewhat evil way is create your ArrayList
as a class variable on your service:
private static ArrayList myList;
This should allow the value of myList
to stick around across instantiations of your service.
Depending on what your code is doing it will be better to read data from the calling Intent
or to persist intermediate data in the service lifecycle methods.
精彩评论