[英]Change app UI from notification action in android
I am working on a To-Do list android app which has the feature of users being able to set reminders which is then shown in the notification bar. 我正在使用待办事项清单android应用程序,该应用程序具有用户能够设置提醒的功能,该提醒随后会显示在通知栏中。 The notification also contains a "Completed" action associated with it.
该通知还包含与之关联的“已完成”操作。 When that action is pressed, it makes some changes to the SQL Lite database.
当按下该操作时,它将对SQL Lite数据库进行一些更改。 Now this works fine if the app was closed.
现在,如果该应用已关闭,则可以正常工作。 But if the app is still open and then I press on the notification action, the UI doesnt change automatically.
但是,如果该应用程序仍处于打开状态,然后我按通知操作,则UI不会自动更改。 I have to close the app and then start it again to see the changed data.
我必须关闭该应用程序,然后再次启动以查看更改的数据。 Is there a way to cause the activity to reload in some way to reflect the changes if the activity was already open.
如果活动已经打开,是否可以通过某种方式使活动重新加载以反映更改。
There are several solutions: 有几种解决方案:
DataProvider
and call context.getContentResolver().notifyChange()
to notify observers about new data with appropriate URI
DataProvider
并调用context.getContentResolver().notifyChange()
通知观察者有关具有适当URI
新数据 LocalBroadcastManager
to register receiver in your Activity and later notify about changes. LocalBroadcastManager
在您的Activity中注册接收者,然后通知有关更改。 So, I recommend you to read about Observer
pattern because all solutions are about it. 因此,我建议您阅读有关
Observer
模式的信息,因为所有解决方案都与此有关。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.