1

I have a TabActivity which loads 2 ListActivity in 2 Tabs. When I click on a list item in either of the ListActivity, I want to pass this value back to the TabActivity. What's the best way to do this? I'm thinking of using a BroadcastReceiver. Any thoughts?

Maurice
  • 6,413
  • 13
  • 51
  • 76

4 Answers4

2

consider this illustration

public class MyTabActivity extends TabActivity
{
      public void onCreate(Bundle b)
      {
            //implementation
      }
      public void setSomeObject(Object someOjbect)
      {
                //will get an object and act accordinglt
      }
}

and in any of your child Activity you would use to set Object like this way:

MyTabActivity myTabParent = (MyTabActivity)this.getParent();
myTabParent.setSomeObject(anyObject);
Adil Soomro
  • 37,609
  • 9
  • 103
  • 153
0

Pass values using intent.

Bundle b=new Bundle();
Intent i=new Intent(this, AnotherActivity.class);
b.putDouble("data", datavalue);//putting the datavalue
i.putExtras(b);

And receive values in AnotherActivity as

double value =  this.getIntent().getDoubleExtra("data", defaultvalue);

Inter Change the lines for both activity and get data from each other.

Sunny
  • 14,522
  • 15
  • 84
  • 129
  • When you load the TabActivity it loads both the activities, how is it possible to pass the intents if it is already loaded? – Maurice Nov 16 '11 at 06:42
0

Still Tab-activity is deprecated.I suggest you to please use Fragments instead of this class and it's provide all your requirements., You can use the v4 support library for these purpose. Thank You

Kiran Babu
  • 1,893
  • 2
  • 13
  • 7
  • You can still use fragments with [android support package](http://developer.android.com/sdk/compatibility-library.html): _The Support Package includes static "support libraries" that you can add to your Android application in order to use APIs that are either not available for older platform versions_ – a.ch. Nov 16 '11 at 07:58
0

Agree with Javanator. I did it the BroadcastReceiver way and it works. Tedious but it works.

Maurice
  • 6,413
  • 13
  • 51
  • 76