0

I am a newbie, trying to execute 2 url queries on the same activity in Android. I managed to get it done using two different AsyncTasks running in parallel.

Both url queries have separate classes and query classes - its two different websites with different data. However i wanted to display it on one screen - one activity.

I initiated both my Loaders with separate loaderIDs

private static final int LOCAL_LOADER_ID = 1;
private static final int GLOBAL_LOADER_ID = 2;

Then i initiated both the loaders . . . .

LoaderManager loaderManager = getLoaderManager();
loaderManager.initLoader(LOCAL_LOADER_ID, null, new LocalLoaderClass());
loaderManager.initLoader(GLOBAL_LOADER_ID, null, new GlobalLoaderClass());

and created the LoaderCallbacks for both of them, so this is an example of the first one one, the second one is the same:

private class GlobalLoaderClass implements 
LoaderManager.LoaderCallbacks<GlobalData>

{

@Override
public Loader<GlobalData> onCreateLoader(int i, Bundle bundle) {

return new GlobalDataLoader(this, CMC_REQUEST_URL);
    }

and so on . . . . . . with the remaining Override methods

However i keep getting an error on the method, i think i am missing something. I have implemented the GlobalDataClass(Context, URL)

matshidis
  • 489
  • 5
  • 11
  • Question is, why do you fire off the AsycTasks using Loaders? There's no need – Chisko Jul 12 '18 at 23:37
  • You can check [here](https://stackoverflow.com/questions/4068984/running-multiple-asynctasks-at-the-same-time-not-possible) or [here](https://stackoverflow.com/questions/23911220/how-run-two-asynctasks-in-one-activity) or [here](https://stackoverflow.com/questions/18357641/is-it-possible-to-run-multiple-asynctask-in-same-time) and I'm sure there's more around, for ideas – Chisko Jul 12 '18 at 23:42
  • I have managed to run both Async Tasks without loaders, however Loaders are supposed to be more efficient in using device resources and mermory. – matshidis Jul 13 '18 at 08:24
  • AsyncTasks are not so good at that when doing http, yet here we are. – Chisko Jul 13 '18 at 17:12

0 Answers0