android-cursorloader

Query songs of an album with CursorLoader

巧了我就是萌 提交于 2019-11-28 21:42:03
问题 I'd like to get the list of songs of an album by querying the MediaStore with CursorLoader How can i do this ? I can get all the songs of the device with this code : static final String[] TRACK_SUMMARY_PROJECTION = { MediaStore.Audio.Media._ID, MediaStore.Audio.Media.TITLE}; public Loader<Cursor> onCreateLoader(int id, Bundle args) { String sortOrder = MediaStore.Audio.Media.TITLE + " ASC"; String select = null; return new CursorLoader(getActivity(), MediaStore.Audio.Media.EXTERNAL_CONTENT

What's the purpose of startManagingCursor?

允我心安 提交于 2019-11-28 18:50:27
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? 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, plus the connection to the content provider that owns the cursor which also means requiring that its process

How to read an SQLite DB in android with a cursorloader?

家住魔仙堡 提交于 2019-11-28 15:19:43
I'm setting up my app so that people can create groups of their friends. When a group is created, it writes 2 tables to the SQL database. The first table has a group name and a group id. The second table has 2 columns, a group id and a user id. This is working fine. However, now I want to be able to read from the database. I'm using a listview fragment with a cursorloader but I'm having trouble getting the information to display. I want to list all the group names from the first table in my list view. My problem is that, when I first used the cursorloader to list my contacts, I was using a Uri

Using CursorLoader with LoaderManager to retrieve images from android apps

谁说我不能喝 提交于 2019-11-28 14:08:52
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 }; Cursor cursor = getContentResolver().query(imageUri, projection, null, null, null); return cursor; }

Android eclipse startManagingCursor Deprecated but want to support older API versions?

痴心易碎 提交于 2019-11-28 10:58:39
I am trying to understand something, and I am sure it is very basic to some people. I read everywhere that the startManagingCursor method is deprecated and you should use the CursorLoader class. But does that mean that you should use the CursorLoader class even for apps that support API levels < 11? Or is it saying that if you intend to only support Honeycomb and up, THEN use cursorLoader? I don't appear to be able to import the cursor loader class with api 4, so i assume that using CursorLoader doesn't apply until Android 3.0+, but can someone verify for me please? Thanks I read everywhere

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

寵の児 提交于 2019-11-28 03:12:28
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? 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 query which lets the user interactively filter the result set through a query input field in the action bar:

How does CursorLoader with LoaderManager know to send the cursor to a CursorAdapter?

╄→尐↘猪︶ㄣ 提交于 2019-11-28 02:51:09
I was going through some of my code and I realized I don't actually know how a CursorLoader and LoaderManager combination used with a CursorAdapter connect. Heres the part that I am confused in. agendaAdapter = new MyAgendaAdapter(this, null); makeProviderBundle(new String[] {"_id", "event_name", "start_date", "start_time", "end_date", "end_time", "location"}, "date(?) >= start_date and date(?) <= end_date", new String[]{getChosenDate(), getChosenDate()}, null); getLoaderManager().initLoader(0, myBundle, MainDisplayActivity.this); list.setAdapter(agendaAdapter); So how does the query() method

How does CursorLoader with LoaderManager know to send the cursor to a CursorAdapter?

放肆的年华 提交于 2019-11-27 19:13:30
问题 I was going through some of my code and I realized I don't actually know how a CursorLoader and LoaderManager combination used with a CursorAdapter connect. Heres the part that I am confused in. agendaAdapter = new MyAgendaAdapter(this, null); makeProviderBundle(new String[] {"_id", "event_name", "start_date", "start_time", "end_date", "end_time", "location"}, "date(?) >= start_date and date(?) <= end_date", new String[]{getChosenDate(), getChosenDate()}, null); getLoaderManager().initLoader

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,