Switching Tabs using Buttons / Cross Activity Communication

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Switching Tabs using Buttons / Cross Activity Communication

Postby Tolrethun » Wed Apr 01, 2009 3:54 pm

Hi there,

I'm trying to write a own std Telephoneapp with Phonebook, Dialpad etc. using SIP ... but this part is not the problem.

I have the problem with TabHost as my Launcher and the Activitys running in it.

Main code looks something like this:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  public class test extends TabActivity {
  2.  
  3.  
  4.  
  5.      @Override
  6.  
  7.      public void onCreate(Bundle icicle) {
  8.  
  9.           super.onCreate(icicle);
  10.  
  11.  
  12.  
  13. ...
  14.  
  15.  
  16.  
  17.           final TabHost tabHost = getTabHost();
  18.  
  19.  
  20.  
  21.           tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("", getRes....)
  22.  
  23.                                   .setContent(new Intent(this, Dialpad.class)));
  24.  
  25.  
  26.  
  27.           tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("", getRes....)
  28.  
  29.                                   .setContent(new Intent(this, Phonebook.class)))
  30.  
  31.  
  32.  
  33. ...
  34.  
  35.      }
  36.  
  37. }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


It's working fine I can switch Tabs an work within the classes/activities as intended etc. Now I want to switch from tab2 to tab1 when one of the phonebook entries is selected. In a further step I want to pass the the phone number to the Activity running in "tab1". So here are the my questions ^^

How can I switch the Tabs when a button in one of the Activities is pressed. (Note: tabHost.setCurrentTab() does not work cause I can't retrieve tabHost within those Activities - at least not yet)

And how can pass data - lets say an integer - from one Activity to another. I'm a little confused with those Intents, BroadcastReceifer etc. so some clarification on this two questions would be nice.

Thanks in ragards, Tol
Tolrethun
Once Poster
Once Poster
 
Posts: 1
Joined: Tue Mar 31, 2009 1:56 pm

Top

Postby wiederke » Thu Apr 02, 2009 12:21 pm

Hi,

to pass data between Activities in the same Application extend the class android.app.Application. In the Android.Manifest.xml set your derived class with the android:name="MyApplication" attribute of the application tag.
You can get the object with getApplication in each activity.


Cheers,

Torsten
wiederke
Experienced Developer
Experienced Developer
 
Posts: 72
Joined: Mon Mar 02, 2009 6:46 pm
Location: Germany

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 7 guests