简体   繁体   中英

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. The notification also contains a "Completed" action associated with it. When that action is pressed, it makes some changes to the SQL Lite database. 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. 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:

  1. Use DataProvider and call context.getContentResolver().notifyChange() to notify observers about new data with appropriate URI
  2. Use LocalBroadcastManager to register receiver in your Activity and later notify about changes.
  3. Use non standard methods of notifying about updated data. For instance Otto

So, I recommend you to read about Observer pattern because all solutions are about it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM