Pass multiple objects to onRetainNonConfigurationInstance
-
08-12-2019 - |
문제
In my app I have to check user location and then connect to server to find out what is the nearest city. It means I have two expensive objects, that I would like to retain on configuration change. One is the task which find out the location, and the other is AsyncTask to retrieve data from server. Now what should I do, to retain both?
My approach is to create a static class in my Activity like this:
static class NonConfigurationObject{
MyLocation myLocationObject;
AsyncTask myAsyncTask;
}
Then when these two objects are created I pass them to this NonConfigurationObject and retain this object and then find out if MyLocation and AsyncTask are there and if there is no need to create them.
Is this a good approach? Because it seems good to me, but I didn't see it done this way anywhere.
EDIT: So this approach seems to be ok. But if you have another way of doing it, please share it.
해결책
This is an acceptable approach as long as you use a static class to avoid leaking memory.