Difference between initLoader and restartLoader in LoaderManager

后端 未结 6 624
春和景丽
春和景丽 2020-12-22 16:17

I\'m completely lost regarding the differences between the initLoader and the restartLoader functions of the LoaderManager:

6条回答
  •  天命终不由人
    2020-12-22 16:52

    initLoader will reuse the the same parameters if the loader already exists. It returns immediately if old data is already loaded, even if you call it with new parameters. The loader should ideally automatically notify the activity of new data. If the screen rotated, initLoader would be called again and the old data would be immediately displayed.

    restartLoader is for when you want to force a reload and change the parameters as well. If you were to make a login screen using loaders, you would call only restartLoader each time the button was clicked. (The button may be clicked multiple times due to incorrect credentials etc.). You would only ever call initLoader when restoring the activity's saved instance state in the event the screen was rotated while a login was in progress.

提交回复
热议问题