1

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

rkmax
  • 17,633
  • 23
  • 91
  • 176

1 Answers1

1

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.

TJ Thind
  • 784
  • 5
  • 17
  • Previously he had been developing my application with minimal api LoaderCallbacks but development is 8 yy so I had to discard, the example uses ``Currently I do not remember exactly what it was, but something that requires the minimum API be 11. the development is focused from api 8 – rkmax Apr 16 '13 at 17:16
  • Even I remember reading the tutorial LoaderCallbacks of vogella – rkmax Apr 16 '13 at 17:17
  • 1
    You can use the Android Support library version of ContentLoader (android.support.v4.contentloader). Judging by the fact you're using Fragments I'd say you're already using the support library. – TJ Thind Apr 16 '13 at 17:32