Zeno
Zeno

Reputation: 591

How do I access a progress bar in a main-activity containing a tabhost from one of the tabs?

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

Answers (2)

alex
alex

Reputation: 31

use getParent() in each tab-Activity

Upvotes: 1

Peter Knego
Peter Knego

Reputation: 80340

Several ways:

  1. 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.

  2. 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

  3. Read how to pass data between Activities.

Upvotes: 0

Related Questions