3

I write an Android app and asking myself how to manage cursors. I know how to get data through a cursor back from the database. I don’t want to handle the lifecycle of these cursors by myself. For Android 2.x and below I used, according to the Android API, methods like managedQuery and startManagingCursor. These methods are now deprecated. Instead of these methods I should use the Loader class for example (CursorLoader). As far as I know CursorLoader must be backed by a ContentProvider. The Android SDK recommends ContentProvider only if I want to share my data. But I just want to write a simple app, where no data should be shared. In all my research I just find tutorials about Loaders in combination with ContentProvider. The SDK says that I can also write my own Loader over the class AsyncTaskLoader. Does someone already have some experience how to implement such a Loader? Are there any best practices? Are there any good tuturials how to implement such a Loader? Or is it just better to implement a ContentProvider, so I can use the CursorLoader (this means a lot of work for just having a managed cursor)?

crimi
  • 746
  • 1
  • 7
  • 8

2 Answers2

0

To make the ContentProvider private use android:exported="false" in your manifest.

Binoy Babu
  • 16,699
  • 17
  • 91
  • 134
0

ContentProviders are easier than you think and are the suggested way by the Android team. See http://responsiveandroid.com/2012/03/19/using-an-android-cursor-loader-with-a-content-provider.html for a good example of creating a ContentProvider.

browep
  • 5,057
  • 5
  • 29
  • 37