大佬教程收集整理的这篇文章主要介绍了Android sqlite begintransaction执行时间过长,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
@Override public ContentProviderresult[] applyBatch(ArrayList<ContentProviderOperation> operations) throws OperationApplicationException { long start = System.currentTimeMillis(); mDbWritable.begintransaction(); long time = System.currentTimeMillis() - start; Alog.i(tag,"Time applyBatch begintransaction: " + timE); final int numOperations = operations.size(); final ContentProviderresult[] results = new ContentProviderresult[numOperations]; try { for (int i = 0; i < numOperations; i++) { results[i] = operations.get(i).apply(this,results,i); } mDbWritable.settransactionsuccessful(); } finally { mDbWritable.endtransaction(); } return results; }
日志中的一些示例:
11-16 15:14:53.726: I/ApiProvider(21442): Time applyBatch begintransaction: 6025 11-16 15:15:00.713: I/ApiProvider(21442): Time applyBatch begintransaction: 4940 11-16 15:15:17.819: I/ApiProvider(21442): Time applyBatch begintransaction: 8651 11-16 15:15:45.346: I/ApiProvider(21442): Time applyBatch begintransaction: 12672 11-16 15:16:16.807: I/ApiProvider(21442): Time applyBatch begintransaction: 12411 11-16 15:16:45.685: I/ApiProvider(21442): Time applyBatch begintransaction: 12247 11-16 15:17:01.500: I/ApiProvider(21442): Time applyBatch begintransaction: 12788
编辑:解析json时我在循环中使用apply batch.例如对于json中的每个项目 – 解析并应用批处理.批处理包含插入,更新,删除操作.
cursor starredChAnnelscursor = mContentResolver.query(ApiContract.ChAnnels.CONTENT_URI,new String[] {Basecolumns._ID,ChAnnelsTable.ID,ChAnnelsTable.SLUG },ChAnnelsTable.IS_STARRED + "=?",new String[] { "1" },null); String userName = mSetTings.getUserName(); if (starredChAnnelscursor != null && starredChAnnelscursor.moveToFirst()) { while (!starredChAnnelscursor.isAfterLast()) { String chAnnelSlug = starredChAnnelscursor.getString(2); ChAnnelHandler chAnnelHandler = new ChAnnelHandler(this); URI chAnnelApiUri = Constants.getChAnnelApiURI(chAnnelSlug,userName); //execute update make applybatch call executeupdate(chAnnelApiUri,chAnnelHandler); starredChAnnelscursor.moveToNext(); } } if (starredChAnnelscursor != null) { starredChAnnelscursor.close(); } /** * Make call to Uri,parse response and apply batch operations to * contentResolver * * @param apiUri * @param handler * - handles parsing */ private Boolean executeupdate(URI apiUri,AbstractJSONHandler handler) { ApiResponse apiResponse = mhttpHelper.dohttpCall(apiUri); ArrayList<ContentProviderOperation> batch = new ArrayList<ContentProviderOperation>(); if (apiResponse != null) { batch = handler.parse(apiResponsE); Alog.v(tag,"update user data from " + apiUri); } if (batch.size() > 0) { try { mContentResolver.applyBatch(ApiContract.CONTENT_AUTHORITY,batch); } catch (Exception E) { Alog.v(tag,"Error: " + e.getmessage()); } } return true; }
以上是大佬教程为你收集整理的Android sqlite begintransaction执行时间过长全部内容,希望文章能够帮你解决Android sqlite begintransaction执行时间过长所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。