android-cursor

Android MVP: safe use Context in Presenter

时光毁灭记忆、已成空白 提交于 2019-12-04 23:07:07
In my app I work with ContentProvider and use LoaderManager.LoaderCallbacks<Cursor>. Fragment (View) public class ArticleCatalogFragment extends BaseFragment implements ArticleCatalogPresenter.View, LoaderManager.LoaderCallbacks<Cursor> { @Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { return onCreateArticleCatalogLoader(args); } @Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { data.registerContentObserver(new LoaderContentObserver(new Handler(), loader)); updateUI(data); } private Loader onCreateArticleCatalogLoader(Bundle args) { int categoryId

android Cursor to JSONArray

若如初见. 提交于 2019-12-04 22:26:04
问题 how can I "convert" a Cursor to a JSONArray? my cursor as 3columns (_id, name, birth) I've searched but I can't not find any examples 回答1: You can't convert the contents of a cursor directly into a JSONObject, but you can do that with some logic. for eg: retrieve the Strings from the cursor, form a String which follows the JSON format, and use it to make a json object : JSONObject jFromCursor=new JSONObject(string_in_JSON_format); 回答2: Cursor to JSONArray public JSONArray cur2Json(Cursor

Using pagination with CursorLoader and MergeCursor closes old cursors

早过忘川 提交于 2019-12-04 18:08:49
As the title says, when trying to paginate a ListView backed by a SimpleCursorAdapter and a CursorLoader , old cursors are getting closed, thus the below exception is being thrown. The first 2 pages load just fine (the first isn't using the MergeCursor and the second page is the first one to use the MergeCursor ). I don't call any close() on any cursor whatsoever. What is interesting is that while debugging, I cannot see the closed flags on any cursor being set as true, for what it's worth. Might be an issue with the MergeCursor then. Let me know if you guys have any solutions, I'm out of

SQLite CursorWindow limit - How to avoid crash

♀尐吖头ヾ 提交于 2019-12-04 16:17:14
I have to execute a query and store the result in a list, the function that I use is this follow : List<SpoolInDB> getSpoolInRecords(String label, boolean getLastInserted) { List<SpoolInDB> spoolInList = new ArrayList<>(); try { if (mdb == null) mdb = mdbHelper.getWritableDatabase(); SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); qb.setTables(TABLE_SPOOLIN); Cursor c = qb.query(mdb, null, " label='" + label + "'", null, null, null, " dateins " + (getLastInserted ? "desc" : "asc")); if (c != null) { c.moveToFirst(); if (c.getCount() > 0) { int ndxid = c.getColumnIndex("id"); int ndxserverID

How to properly close a cursor in android

梦想与她 提交于 2019-12-04 11:45:18
问题 I have this database using sqlite, and I'm having problem with closing the cursor its saying that Application did not close the cursor or database object that was opened here here's the logcat 10-18 08:40:56.354: E/Cursor(331): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here 10-18 08:40:56.354: E/Cursor(331): at android.database.sqlite.SQLiteCursor.<init>(SQLiteCursor.java:210) 10-18 08:40:56.354: E/Cursor

Cursor index out of bound exception on listview cllick event

不羁的心 提交于 2019-12-04 06:56:25
问题 I am performing a sqlite database operation on click event of listview as shown below: ListView lv1 = (ListView) findViewById(R.id.listView1); lv1.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { String out = arg0.getItemAtPosition(arg2).toString(); SQLiteDatabase db = openOrCreateDatabase("mynotedb", MODE_PRIVATE, null); String sql = "select description from notecont where title='"+out+"'"; Cursor c1 = db

how to select unique contacts from android

隐身守侯 提交于 2019-12-04 05:53:49
i want to select unique contacts from android only that contacts which have phone numbers. i am using this code ContentResolver cr = getContentResolver(); Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, ContactsContract.Contacts.DISPLAY_NAME); // Find the ListView resource. mainListView = (ListView) findViewById(R.id.mainListView); // When item is tapped, toggle checked properties of CheckBox and // Planet. mainListView .setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View item, int position, long id)

MediaStore.Images.Thumbnails.getThumbnail returns wrong thumbnail instead of NULL

社会主义新天地 提交于 2019-12-04 02:08:50
Consider the scenario as in this picture: Three photos, one of them is a large GIF file (3MP). I'm querying MediaStore in order to retrieve the correspondent thumbnails. If I initialize the Cursor via CursorLoader with this sortOrder: MediaStore.Images.Media.DATE_ADDED + " DESC"" What happens: MediaStore returns the previous successfully retrieved thumbnail: Expected behaviour: when MediaStore cannot retrieve the thumbnail of a given image for some reason it has to return NULL, as per its Javadoc: "... Returns A Bitmap instance. It could be null if the original image associated with origId

When to close Cursor used in SimpleCursorAdapter

浪尽此生 提交于 2019-12-04 00:01:28
I'm using a SimpleCursorAdapter to display results in a ListView but since I've got to query my database lots of times during a search (using the SearchView widget) it worries me that the cursor might be left opened. This is how I query my database and show the results in a ListView: class SearchCustomers extends AsyncTask<String,Void,Cursor>{ @Override protected Cursor doInBackground(String... params) { //get the query String query=params[0].toLowerCase(Locale.getDefault()); Cursor cursor=mDB.searchCustomersByName((query != null ? query : "@@@@")); return cursor; } @Override protected void

Android database - Cannot perform this operation because the connection pool has been closed

好久不见. 提交于 2019-12-03 23:34:44
I have strange problem with android database and cursors. Time to time (very rarely) happens, that I got crash report from customers. It's hard to find out why it crashes, as I have ~ 150 000 active users and maybe 1 report per week or so, so it's really some minor bug. Here is exception: STACK_TRACE=java.lang.IllegalStateException: Cannot perform this operation because the connection pool has been closed. at android.database.sqlite.SQLiteConnectionPool.throwIfClosedLocked(SQLiteConnectionPool.java:962) at android.database.sqlite.SQLiteConnectionPool.waitForConnection(SQLiteConnectionPool.java