Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the appropriate replacement of deprecated getSupportLoaderManager()?

I came to know that getSupportLoaderManager is deprecated. But I want to call:

getSupportLoaderManager().initLoader(0, null, mRecipeLoaderManager);

What should be an alternative to that call? Or can I still use getSupportLoaderManager without worrying?

like image 699
fabi Avatar asked Jul 18 '18 17:07

fabi


3 Answers

I also had this issue too and this code solved it for me LoaderManager.getInstance(this).initLoader(0,null,mRecipeLoaderManager);

i hope it helps

like image 178
amos godwin Avatar answered Dec 15 '22 06:12

amos godwin


The reason why this method is deprecated is because Loaders have been unbundled from their historical Fragment and FragmentActivity implementations in order to live in their own library that will soon be an optional dependency, and their implementation has been rewritten on top of architecture components.

The unbundled way of retrieving a LoaderManager instance is to use the static factory method:

LoaderManager.getInstance(T)

where T is an instance of both LifecycleOwner and ViewModelStoreOwner (the main implementations being FragmentActivity and Fragment).

like image 35
BladeCoder Avatar answered Dec 15 '22 05:12

BladeCoder


As stated here: Loaders

"Loaders have been deprecated as of Android P (API 28). The recommended option for dealing with loading data while handling the Activity and Fragment lifecycles is to use a combination of ViewModels and LiveData."

Whenever you see something is deprecated, go directly to the developer api reference site and review the class or function for which you're looking and if there is an equivalent alternative.

like image 37
Kavin Prabhu Avatar answered Dec 15 '22 06:12

Kavin Prabhu