0

I have two activities A & B. I have implemented Loaders in both activities as I will be needing same data in both activities.

onCreateLoader() method of both activities will be called every time or just at the time of loader creation ?

Example : If Activity "A" is called and loader is created then same loader will be exist in memory and when activity "B" is called, It will reuse the same loader but onCreateLoader() of activity "B" will be called ?

Amey Jahagirdar
  • 455
  • 1
  • 4
  • 14
  • You can find out by adding Log statements to your project – rhari Nov 22 '16 at 08:43
  • Yes, Thats the problem Log methods are showing logs in both onCreateLoader() methods, My concern is whether theoretically it should invoke onCreateLoader() or not – Amey Jahagirdar Nov 22 '16 at 08:54
  • 1
    If an old Loader was being used, then onRestartLoader() would be called, which should result in a call to onCreateLoader() according to http://stackoverflow.com/questions/21253332/will-loadermanager-restartloader-always-result-in-a-call-to-oncreateloader. So it shouldn't be an issue. – rhari Nov 22 '16 at 09:05
  • If I call same loaders in 2nd activity with the exactly same procedure, Does it matter ? or do I need to take care of whether loader is already present or not – Amey Jahagirdar Nov 22 '16 at 10:43
  • By same loader you mean same class or same Loader object that was created in the first activity ? – rhari Nov 22 '16 at 11:00
  • Yes By using same loader, i.e by calling getLoaderManager().initLoader(0, null, this); in both activities – Amey Jahagirdar Nov 22 '16 at 12:47
  • As long as you are creating and returning a new Loader object inside onCreateLoader(), in should be fine. – rhari Nov 22 '16 at 13:09

0 Answers0