android-loadermanager

Android error: java.lang.IllegalStateException: trying to requery an already closed cursor

一世执手 提交于 2019-11-27 12:59:02
问题 environment (Linux/Eclipse Dev for Xoom Tablet running HoneyComb 3.0.1) In my app I'm using the camera (startIntentForResult()) to take a picture. After the picture is taken I get the onActivityResult() callback and am able to load a Bitmap using a Uri passed via the "take picture" intent. At that point my activity is resumed and I get an error trying to reload the images into a gallery: FATAL EXCEPTION: main ERROR/AndroidRuntime(4148): java.lang.RuntimeException: Unable to resume activity {.

How to properly insert values into the SQLite database using ContentProvider's insert() method through a CursorLoader?

不羁的心 提交于 2019-11-27 12:44:31
问题 I was reading the doc, but I am still not too sure. Its says to use getContentResolver() , but then that really isn't using CursorLoader. So is there a way to do it through CursorLoader ? I know how to do it with query() . Are the steps very similar? Even just a link that explains exactly this would be helpful. Please note, do not link me to the Google doc as they do not have an example that ever uses the insert() method from ContentProvider using a CursorLoader . Thanks in advance!! Edit: I

What's the purpose of startManagingCursor?

左心房为你撑大大i 提交于 2019-11-27 11:41:30
问题 Ok, the documentation states that it lets the Activity manage the cursor's lifecycle. But I don't really see the point of it since when the activity is destroyed, any references to the newly created cursor should be also erased and then the cursor itself is left to perish in the next garbage collecting cycle. So why bother? 回答1: You should not rely on cursors being destroyed by the garbage collector... a cursor represents a significant amount of resources: all of the data held by the cursor,

Is it OK to have one instance of SQLiteOpenHelper shared by all Activities in an Android application?

大兔子大兔子 提交于 2019-11-27 10:29:53
Would it be OK to have a single instance of SQLiteOpenHelper as a member of a subclassed Application, and have all Activities that need an instance of SQLiteDatabase get it from the one helper? Having a single SQLiteOpenHelper instance can help in threading cases. Since all threads would share the common SQLiteDatabase , synchronization of operations is provided. However, I wouldn't make a subclass of Application . Just have a static data member that is your SQLiteOpenHelper . Both approaches give you something accessible from anywhere. However, there is only one subclass of Application ,

Using CursorLoader with LoaderManager to retrieve images from android apps

风流意气都作罢 提交于 2019-11-27 08:18:28
问题 At the moment I’m using getContentResolver().query()/managedQuery() to get a cursor to retrieve images from the gallery app. Because the APIs I’m using are partly deprecated I wanted to use CursorLoader with LoaderManager. /** * Creates a cursor to access the content defined by the image uri for API * version 11 and newer. * * @return The created cursor. */ @TargetApi(Build.VERSION_CODES.HONEYCOMB) private Cursor createCursorHoneycomb() { String[] projection = { MediaStore.Images.Media.DATA }

Android 3.0 - what are the advantages of using LoaderManager instances exactly?

北城余情 提交于 2019-11-27 05:05:06
问题 With 3.0 we got the fancy LoaderManager , which handles data loading using the AsyncTaskLoader , the CursorLoader , and other custom Loader instances. But reading through the docs for these I just couldn't get the point: how are these better than just using the good old AsyncTask for data loading? 回答1: Well they are a lot simpler to implement, and take care of everything about lifecycle management so are much less error prone. Just look at the sample code, for showing the result of a cursor

Can you use a LoaderManager from a Service?

为君一笑 提交于 2019-11-27 00:41:59
问题 I have a data loading system set up using a custom Loader and Cursor that is working great from Activities and Fragments but there is no LoaderManager (that I can find) in Service. Does anyone know why LoaderManager was excluded from Service? If not is there a way around this? 回答1: Does anyone know why LoaderManager was excluded from Service? As stated in the other answer, LoaderManager was explicitly designed to manage Loaders through the lifecycles of Acivities and Fragments . Since

CursorLoader not updating after data change

给你一囗甜甜゛ 提交于 2019-11-27 00:17:42
I have created a small application, trying to understand the functionality of the LoaderManager and CursorLoader -classes. I have implemented LoaderCallbacks<Cursor> on my FragmentActivity -class and everything works fine, except the fact that when I update my data via ContentResolver.update() or ContentResolver.insert() -methods, onLoadFinished() is not called and as a result my data doesn't update. I have a custom ContentProvider and I am wondering if the problem is in my ContentProvider not notifying that the data changed or something else. Did you call setNotificationUri(ContentResolver cr

What are the benefits of CursorLoaders?

不想你离开。 提交于 2019-11-26 19:15:14
问题 I use Cursors extensively in my app, to load and occasionally write information from and to a database. I have seen that Honeycomb and the Compatibility Package have new Loader classes designed to help with loading data in a "good" way. Essentially, are these new classes (in particular CursorLoader ) considerably better than previous methods of managing data? What is the benefit of a CursorLoader over managed Cursors for example? And I use a ContentProvider to deal with data, which obviously

getLoaderManager().initLoader() doesn't accept 'this' as argument though the class (ListFragment) implements LoaderManager.LoaderCallbacks<Cursor>

北城以北 提交于 2019-11-26 19:05:00
问题 I'm having trouble following a guide on using SQLite in Android. I'm using a ListFragment instead of a ListActivity (as in the example), so I have the ListFragment implement LoaderManager.LoaderCallbacks<Cursor> instead. Then, in the fillData() method in the ListFragment : private void fillData() { // Fields from the database (projection) // Must include the _id column for the adapter to work String[] from = new String[] { NotesSQLiteHelper.COLUMN_TITLE }; // Fields on the UI to which we map