in my application I store data in a database (sqlite). For display, I use the expandedlistview on the activity. In order not to load the processor with database calls, I created a static variable in the service in which I store the actual data.

public class NetworkService extends Service { private static List<RouteTask> routeTaskList; public static void setRouteTaskList(List<RouteTask> rtList) { routeTaskList = rtList ; } public static List<RouteTask> getRouteTask(){ return routeTaskList; } } 

Data is loaded from the server in AsynkTask

 public class LoadRoutesTask extends AsyncTask<Object, Object, RoutesResponse> { private final String url = ApplicationSettings.SERVER_URL + ApplicationSettings.GET_ROUTE_DRIVER_DATE_URL; public LoadRoutesTask(Context ctx, TaskLoadListener listener) { this.listener = listener; this.ctx = ctx; } @Override protected void onPostExecute(RoutesResponse result) { } @Override protected RoutesResponse doInBackground(Object... params) { String email = (String) params[0]; String sessionID = (String) params[1]; int pageSize = (int) params[2]; int pageNumber = (int) params[3]; String order = (String) params[4]; long date = (Long) params[5]; date = date - date % 86400000; // upload all status updates and remove them from pending in case succesfully AuthResponse authResponse = null; //TODO: загрузка только для тек драйвера ---------------------------------------------- StatusChangedManager scManager = new StatusChangedManager(ctx); List<StatusChanged> statusChangerList = scManager.getByUserName(email); if (statusChangerList != null) { for (StatusChanged sc : statusChangerList) { UpdateStatusRequest updateStatusRequest = new UpdateStatusRequest( email, sessionID, sc); HttpService<AuthResponse, UpdateStatusRequest> httpService = new HttpService<>( AuthResponse.class); authResponse = httpService.Post(updateStatusUrl, updateStatusRequest); if (authResponse.getStatus().equals("SUCCESS")) { scManager.delete(sc.getTaskID()); } } } } 

I separately announced the listener interface

 public interface TaskLoadListener { public int loadProgress(int progress); public void loadCompleted(); public void wasError(); } 

which implements activit. The call from asynTask to the activation occurs through the implementation of the interface. How to remove the listener interface from this scheme and make loading according to android development standards?

    1 answer 1

    This is not quite the right architectural solution. When implementing this task, you should use the following link: Database - Cursor - CursorAdapter - Expandedlistview. To get the Cursor, use the CursorLoader. And as CursorLoader is a subclass of AsyncTaskLoader, it already uses AsyncTask to work with data in a separate stream.