0

I am relatively new to android programming and I am currently developing an android app with Mono Android (Xamarin). I can also convert java solution to C# so don't worry about posting java solutions :). Now to the scenario,

My app flow is like follows;

User starts the app --> App executes a background thread to check for item updates --> User is allowed to navigate through app while the thread is returned --> if there are updates, the current visible activity should show a HUD and the items must be updated.

I have tried to implement above by creating a broadcast receiver that notifies when there are updates. I then derive all the activities from a base class which listens to this broadcast and shows the HUD loader.

However, it seems all the activities in the backstack are also notified when there is an update and the same code segment that shows the HUD loader is executed multiple times. Is there any specific way to notify the top most (application owned & visible) activity so that the loader is shown only one time? Or is there any other way I could achieve this other than using broadcast receivers? Any help on this would be greatly appreciated.

Much Overflow
  • 3,142
  • 1
  • 23
  • 40
  • 1
    You may try to use the OnStart() and OnStop() callbacks to register and un-register your receiver. See if this helps http://stackoverflow.com/questions/7887169/android-when-to-register-unregister-broadcast-receivers-created-in-an-activity – Jatin Jan 22 '15 at 14:54
  • That did the trick, Thanks. If you post this as answer I can accept it – Much Overflow Jan 22 '15 at 15:04

1 Answers1

1

One way of achieving it would be to register and un-register your broadcast receiver in the OnStart() and OnStop() callback as explained here. For more on Android lifecycle callbacks refer this guide

Community
  • 1
  • 1
Jatin
  • 4,023
  • 10
  • 60
  • 107