简体   繁体   中英

Notify database changes to fragment from Service, Activity, Fragment, etc

My app have many fragments, many of them extends from ListFragment and have Adapters for read database (SQLite). My app have only one Activity (for now) and have a Service is binded when the Activity start.

My problem is how to notify to a fragment when are changes in the database from the service or other fragment.

Example of architecture of my application

MainActivity
  tabhost
   fragment
     listfragment
     listfragment
   fragment
     fragment
     gridfragment
   fragment

MainService
  comunication_server
    send_data
    receive_data

As you can see my application has several fragments, and I want to inform the fragments that the data has changed. or at least launch an internal broadcast can hear by fragments like iNotifyPropertyChange .NET C#/WPF

Think about implementing CursorLoaders. They'll give you the ability to load your lists asynchronously and they will monitor the source of your data for changes and update lists automatically. They're super easy to implement.

Lars Vogal has a neat little tutorial on them.

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