Android Fragment - Using activity's loadermanager instead of Fragment's. Is it Ok?

Viewed 3429

Given a fragment which loads (a lot of) data from the database using a loader.

Problem :

I have a pager adapter which destroys the fragment when the user moves away from the tab holding it and recreates it when user gets back to that tab. Because of this recreation, a new loader is created everytime and the data gets loaded everytime.

Question :

To avoid recreating loader everytime the fragment is created, is it ok to use getActivity.getSupportLoaderManager.initLoader(loaderId, null, false) in the onActivityCreated method of the fragment?

I have tried it, tested it and it seems to be working fine. But I'm not convinced that it is right.

2 Answers
Related