[英]1st Activity's listview not updated after 2nd activity inserts into database via ContentProvider; onLoadFinished not called
Problem: upon returning from a 2nd activity the first activity's listview does not reflect database changes made by the 2nd activity. 问题:从第二个活动返回时,第一个活动的列表视图无法反映第二个活动对数据库所做的更改。 If I make a trivial change to code (to make emulator happy) and refire the app the listview now accurately shows the database changes the 2nd Activity made during the last session.
如果我对代码进行了微不足道的更改(使模拟器满意)并重新启动应用程序,则listview现在可以准确显示数据库在上一个会话期间所做的第二次活动更改。
The guts of the app: 该应用程序的勇气:
MainActivity: extends Activity implements LoaderManager.LoaderCallbacks<Cursor>
=>onCreate: SimpleCursorAdapter set; getLoaderManager().initLoader(LOADER_ID, null, this)
=>onResume: super.onResume(); getLoaderManager().restartLoader(0, null, this)
...oh my gawd! ...哦,我的天哪! There's the problem: initLoader and restartLoader are using different loader ID's.
有一个问题:initLoader和restartLoader使用不同的加载器ID。
This stumped me for the last five hours. 最近五个小时让我感到难过。 Why I am leaving this question: in trying to solve my problem I didn't run into this answer (maybe it's just too bone-headed of a thing to suggest someone look for) but for the next person who stumbles in this unique way, here's a potential answer.
为什么我要离开这个问题:在尝试解决我的问题时,我没有遇到这个答案(也许这太笨拙,无法建议某人寻找),但是对于下一个以这种独特方式绊倒的人,这是一个潜在的答案。
Make sure LoaderManager ID's are the same in initLoader and restartLoader. 确保initLoader和restartLoader中的LoaderManager ID相同。
In addition to all the other posts by Alex and CommonsWare and all the rest of them that you will run into while searching for the solution to your failing-to-update listview, this is something else that might have happened to you. 除了Alex和CommonsWare撰写的所有其他文章,以及在寻找无法更新列表视图的解决方案时遇到的所有其他文章,这可能是您发生的其他事情。
During my searching for what could be wrong I also noted I had not implemented: cursor.setNotificationUri(getContext().getContentResolver(), uri); 在搜索可能出了什么问题的过程中,我还指出我没有实现:cursor.setNotificationUri(getContext()。getContentResolver(),uri);
( How do CursorLoader automatically updates the view even if the app is inactive? ) ( 即使应用程序处于非活动状态,CursorLoader如何自动更新视图? )
...two different tutorials I was following for how to implement content providers did not have that setContentNotificationUri in their providers' query methods; ...我正在遵循的两个有关如何实现内容提供程序的教程在其提供程序的查询方法中没有setContentNotificationUri; though they used a querybuilder and I did not (maybe setContentNotificationUri is included in the queryBuilder? Quick research didn't suggest that was the case).
尽管他们使用了querybuilder,但我没有使用(也许setContentNotificationUri包含在queryBuilder中?快速研究并未发现是这种情况)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.