简体   繁体   English

在第二个活动通过ContentProvider插入数据库后,第一个活动的列表视图未更新; onLoadFinished不被调用

[英]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.

相关问题 完成第二个活动(由第一个活动调用)后如何在第一个活动中调用onCreate方法 - How to call onCreate method in 1st activity after finishing 2nd activity(which is called by the 1st activity) 当我返回到第一个活动时,第二个活动未调用第二个活动的onCreate()函数 - When I return back to 1st Activity the onCreate() function of 2nd Activity is not called in 2nd time 无法通过getIntent()将第一个活动的textview值传递给第二个活动的textview - Unable to pass 1st activity's textview value to 2nd activity's textview through getIntent() 如何在第一个活动中调用第二个活动值? - how to call 2nd activity value in 1st activity? 如何从第二活动到第一活动获取数据 - How to get data from 2nd Activity to 1st Activity 将第1个活动的值传递给android中的第2个活动 - Pass the value from 1st activity to 2nd activity in android 从第一个活动转到第二个活动时出错 - error when going from 1st activity to 2nd activity 从第一个活动中获取意图后如何刷新第二个活动 - How to refresh 2nd activity after intent from 1st activity 从第一个活动拨打电话后,第二个活动没有通话 - 2nd Activity doesn't call after calling from 1st Activity 在不丢失更新数据的情况下将第二个活动的价值保存到第一个活动 - Saving value from 2nd activity to 1st without losing the updated data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM