Question

If I do need it, I'll have to modify about 15 classes (models and model-manager classes), so I really want to know if I need a ContentProvider.

Here's where I am:

  1. Similar to Twitter, I'm getting rows of data from a server, and saving it locally in case the user has no Internet connection. But the ideal way is to always get it from the Server.

  2. I am probably not going to use SimpleCursorAdapter because the rows of data I get from the server includes URLs, which means I have to create a custom adapter to display images.

  3. I need to load data into the ListViews asynchronously because I'm having a ViewPager with 3 Fragments that shows the same data (different filters tho), so, since a ViewPager loads 3 Fragments into memory, it means 3 queries are executing (and that's most likely the cause of non-smooth swiping).

So far, the way I synchronize data between the App and the Server is:

  • Fragment.onStart() executes an AsyncTask which returns rows of data formatted as JSON data
  • Said AsycTask.onPostExecute() updates the List<E> and calls Adapter.notifyDataSetChanged()

The issue here is that each time I change tabs, the onStart() is called, ergo the AsyncTask executes causing the UI not being smooth.

Should I change the way I synchronize data with the Server, or should I use ContentProvider?

EDIT: as a head up, the reason I'm asking is that startManagingCursor() method is depracated. It says to use the Loader framework, but it seems it's only available through ContentProvider

Was it helpful?

Solution 2

I wrote a custom CursorLoader based on the SimpleCursorLoader source code that comes within the support library. You can search this site for more information about writing a custom one.

OTHER TIPS

You don't need to develop your own provider if you don't intend to share your data with other applications. However, you do need your own provider to provide custom search suggestions in your own application. You also need your own provider if you want to copy and paste complex data or files from your application to other applications.

from http://developer.android.com/guide/topics/providers/content-providers.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top