Вопрос

I have a MyListFragment implementation which uses MyCursorAdapter. As the names suggest, they both extend the respective Android classes.

I read through this Loader/LoaderManager tutorial. So, now my query happens in

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) { 
        return new CursorLoader(blah1, blah2, blah3, blah4, blah5, blah6);
}

and the LoaderManager along with the Loader takes care of when to re-query and update, runs separate threads for queries, synchronize without having me to worry about it. So far so good.

I have 2 questions:

1) I have implemented a MyContentProvider. Where does this come into picture?
-> It seems that the above new CursorLoader(......) makes the query through the MyContentProvider since it uses the URI as the first argument.

2) I also need to delete / update / insert items in the list. Should I just call my the respective methods from MyContentProvider inside MyListFragment at the desired places? If yes, then can I also load the items manually, without having the loader handle it? If not, then what is the right way to do it? I did not find any information online. Any pointers appreciated.

Это было полезно?

Решение

  1. Yes, thats correct it will call the query method in MyContentProvider with the arguments used in the CursorLoader constructor.

  2. If I understood that correctly the answer is yes you can just call the MyContentProvider methods as long as they are calling ContentResolver.notifyChange() as it will cause the CursorLoader to get a new cursor (this is the whole point of using CursorLoader). When using CursorLoader you should avoid manually changing the data at all if you can so as to allow what is shown to always reflect the current set of data coming from MyContentProvider.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top