TabActivity issue

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

TabActivity issue

Postby williamzanelli » Tue May 12, 2009 6:40 pm

Hey guys,

I was wondering, say if you have a Tabhost with 4 tabs.

Each Tab has an activty associated with it.

When you click one Tab to the next, does the previous Tab's activty get discarded/paused or what??

Thanks in advance for your thoughts...

Will
Will
williamzanelli
Experienced Developer
Experienced Developer
 
Posts: 63
Joined: Mon Jan 05, 2009 2:37 am
Location: UK

Top

Reply

Postby satishkumar_lskin » Wed May 13, 2009 8:21 am

Hi,

Can I know why u need to know the state of an Activity that is associated with each tab ? When u switch to a new tab, the content view of the activity associated with the previous tab remains as it is.
For example, u may have used :
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  tab1Activity.setContentView(layout1);
  2.  
  3.            tab2Activity.setContentView(layout2);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Here on switching to tab2, layout1 of tab1 remains as it is. If u want to change the content of tab1 on a UI event like button click on that tab , u can use
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. tab1Activity.setContentView(newLayout);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4

A better approach would be something like this : Say for example , ur layout1 is a LinearLayout with Vertical orientation. Say in ur View hierarchy , u have added another LinearLayout as the first child of layout1. On a button click, u want to change the tab1's content. Now simply replace the first child of layout1 with the new layout.

For example,
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. layout1.addViewAt(childLinearLayout , 0 );
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


Now on a button click,
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. layout1.addViewAt(newLinearLayout , 0 );
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


Regards,
Satish
satishkumar_lskin
Developer
Developer
 
Posts: 32
Joined: Mon Oct 20, 2008 8:15 am
Location: Coimbatore , TamilNadu, India

Postby williamzanelli » Wed May 13, 2009 4:31 pm

Hi Satish,

Thanks for the detailed message.

I have 3 tabs, each one consisting of ListActivity - each list is updated dynamically when some external data from a webserver changes.

So to make this application efficient, I wanted to know if, when a user scrolls from tab-tab, would the the an activity associated with one tab be discarded?

i'm still not sure what happens in depth in the code, but I can tell you from my logs, when you swicth from tab to the next, the previous tabs "Thread" (which was used to update it) - is "discarded" or "paused" - so i've got the app to do what I want it to do.. :-)

Here's some of my code
Code: Select all
public void onStop() {
      this.myThread.interrupt();
      super.onStop();
   }

   public void onDestroy() {
      this.myThread.interrupt();
      super.onDestroy();
   }

   public void onPause() {
      super.onPause();
      Log.i("RefreshThread", "RefreshThread Terminated...");
      this.myThread.interrupt();
   }
   
   public void onResume(){
      super.onResume();
      
   }





Maybe someone can enlighten me with the internal workings??

My guess is when you switch tabs, a "pause" method is called somehwere. Any ideas?

Thanks for your help and time

Will
Will
williamzanelli
Experienced Developer
Experienced Developer
 
Posts: 63
Joined: Mon Jan 05, 2009 2:37 am
Location: UK

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 6 guests