Maurice
Maurice

Reputation: 6433

Android Best way to pass values from Tabs to Main TabActivity

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?

Upvotes: 1

Views: 1198

Answers (4)

Maurice
Maurice

Reputation: 6433

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

Upvotes: 0

Adil Soomro
Adil Soomro

Reputation: 37729

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);

Upvotes: 2

Kiran Babu
Kiran Babu

Reputation: 1893

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

Upvotes: 0

Sunny
Sunny

Reputation: 14818

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.

Upvotes: 0

Related Questions