Question

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.

Was it helpful?

Solution

This is an acceptable approach as long as you use a static class to avoid leaking memory.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top