udacity / Sunshine-Version-2

The official repository for Developing Android Apps
Apache License 2.0
2.87k stars 4.41k forks source link

Listview only syncing when activity restarts #330

Closed RicardEjarque closed 7 years ago

RicardEjarque commented 7 years ago

Hi,

I just finished implementing the CursorLoader on Sunshine. I see that now (with my version and with the 'official' version here in github) the listview is only refreshed when the app is completely restarted (i.e. app closed and reopened). The listview is not changed when doing Refresh, when rotating or when changing location.

I don't know if this is the expected behaviour... It makes sense that when rotating the loader is not affected, but when changing the location I would expect the data to change.

Do you know if this is something to be resolved in the next sections of the course, or the expected behavior?

Thanks,

Ricard

RicardEjarque commented 7 years ago

I think I now understand why the listview does not update when the location setting is changed.

Our onCreateLoader function includes the location based on the setting, but the function is only called when the activity is created (initLoader is done in onActivityCreated). Thus, even if the loader is notified of the changes, it uses the old uri (including the old location) to make the query, obtaining the old results instead of the new ones.

Any idea on how to solve this? I think that one good way would be for the settingsActivity to inform the MainActivity when a setting has changed, so the MainActivity can then restart the loader. What do you think about that?