Reputation: 591
I am developing an android application where I have a main-activity that contains a progress bar and a tabhost. the tabhost has 3 tabs.
How do I from a tab-activity access the progress bar in the main activity? I want to be able to start and stop the progress bar when things changes inside each tab ativity...
Upvotes: 0
Views: 677
Reputation: 80340
Several ways:
Couple the classes together: create a custom Application and save a weak reference to ProgressBar to a field. Use getApplication()
inside tab activities and cast it to your custom Application.
Note: Use weak reference inside your Application class to prevent memory leaks.
Create your own Broadcast
and BroadcastReceiver
, where tab activities send broadcasts and progress bar listens to them: http://developer.android.com/guide/appendix/faq/commontasks.html#broadcastreceivers
Read how to pass data between Activities.
Upvotes: 0