TabActivity Lifecycle

by JasonMP » Sat, 21 Nov 2009 03:02:44 GMT


Sponsored Links
 Hi,

Can someone explain to me, or point me to a reference document
describing a TabActivities Lifecycle?  I have a tab that runs an
activity.  When does that activities onCreate, onResume, onPause take
place?

--



TabActivity Lifecycle

by JasonMP » Sat, 21 Nov 2009 03:55:11 GMT


 Reason for confusion:

I start my app and it loads to default TAB1.

I select TAB2 at the top and it switches to TAB2...in my onResume()
for TAB2 I display a Toast "Hello" and it is displayed.

I go back to TAB1....everything ok here.

i go back to TAB2....no Toast displayed from the onResume().

What am I missing?




--


Sponsored Links


TabActivity Lifecycle

by Mark Murphy » Sat, 21 Nov 2009 04:01:37 GMT


 


I take it that TAB2 is using an Intent to load an activity in the
contents of the tab.

One of these days, I'm going to figure out why people keep using this
rather than just using simple Views for tab content. Using activities
adds extra complexity for no obvious added value. Maybe I need sterner
language in my book...

Regardless, if my above assumption is correct, the reason onResume() is
called here is that the activity is first being created, and onResume()
is called as part of the creation path, after onCreate() and onStart().


Correct, because the in-tab activity already exists and was not paused.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://twitter.com/commonsguy 

Android Development Wiki:  http://wiki.andmob.org 

--



TabActivity Lifecycle

by Jason Mallet-Prevost » Sat, 21 Nov 2009 04:08:49 GMT


 Hi Mark, I owe you one after today haha.  So in order to keep it all
together in the same activity I would just create a separate Layout in my
XML file and give it an ID I can pass to the TabHost?  And then since its
all in the same activity I can use onTabChanged() to run any updates to my
database/adapters/cursors?






>



TabActivity Lifecycle

by Mark Murphy » Sat, 21 Nov 2009 04:18:42 GMT


 


Yes on all counts. Here's an example of using Views instead of activities:

 http://github.com/commonsguy/cw-android/tree/master/Fancy/Tab/ 

And, here's an example of adding additional tabs on the fly:

 http://github.com/commonsguy/cw-android/tree/master/Fancy/DynamicTab/ 

I don't have example code up that demonstrates the onTabChanged() stuff,
but I have used it, and it works pretty much as one might expect.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://twitter.com/commonsguy 

_The Busy Coder's Guide to Android Development_ Version 2.8
Available!

--



TabActivity Lifecycle

by Jason Mallet-Prevost » Sat, 21 Nov 2009 04:26:27 GMT


 Ok, I'm running into a hitch.  Using setListAdapter() inside my TabActivity
is making Android upset.  Is there some other way to populate a tab with a
ListView?






>



TabActivity Lifecycle

by Mark Murphy » Sat, 21 Nov 2009 04:29:37 GMT


 


Step #1: Get the ListView via findViewById(), like any other widget

Step #2: Call setAdapter() on the ListView

Step #3: Drink beer

Please, the order of these steps is important -- we don't want any
accidents related to CUI (Coding Under the Influence).

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://twitter.com/commonsguy 

_The Busy Coder's Guide to Android Development_ Version 2.8
Available!

--



TabActivity Lifecycle

by Jason Proctor » Sat, 21 Nov 2009 04:32:45 GMT


 >Please, the order of these steps is important -- we don't want any

not necessarily --

 http://xkcd.com/323/ 

:-)

-- 
jason.vp.engineering.particle

--



TabActivity Lifecycle

by Jason Mallet-Prevost » Sat, 21 Nov 2009 04:37:01 GMT


 Yeah, I think I got a little carried away there.  I slowed down and got it
figured out.  Thanks again Mark.

On Fri, Nov 20, 2009 at 3:32 PM, Jason Proctor <



>



TabActivity Lifecycle

by JasonMP » Sat, 21 Nov 2009 04:51:12 GMT


 Heres another concern.  I previously had 2 separate contextmenus and 2
separate options menus for my first tab and my second tab.  Now that
they are in the same activity do they have to share the same menus?
I'm guessing I can always run a switch statement or something when I
open the menu based off which tab is presently open but that just
seems like the wrong way to do it.  I'm sorry if these are painfully
obvious, I'm still learning the ropes here.




> >



TabActivity Lifecycle

by Mark Murphy » Sat, 21 Nov 2009 04:53:44 GMT


 


Option menu, yes; context menu, no. Option menus are per activity.
Context menus are per widget, and your roster of widgets has not changed.

BTW, did you actually had two separate option menus working, one per
tab, defined via that tab's activity? I never tried that with
activities-in-tabs. That'd be one benefit to having activities in tabs.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://twitter.com/commonsguy 

_Android Programming Tutorials_ Version 1.0 In Print!

--



TabActivity Lifecycle

by Jason Mallet-Prevost » Sat, 21 Nov 2009 05:02:15 GMT


 Yeah, I had a separate menu in each of my Tabs, and so far they worked
flawlessly.

I'll have to read up on context menus a little more when I get the chance.
 Right now I have 2 Views with contextMenus called as
registerForContextMenu(View1); and  registerForContextMenu(View2); and
theyre both pulling up the same menu.







>



TabActivity Lifecycle

by Mark Murphy » Sat, 21 Nov 2009 05:15:28 GMT


 


onCreateContextMenu() is passed the View for which you need to create
the context menu. Hence, in your case, it'll be called twice, and you'll
need to examine the passed-in View to figure out which list is which.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://twitter.com/commonsguy 

_Android Programming Tutorials_ Version 1.0 In Print!

--



Other Threads

1. regarding facebook and twitter api integration




Questions regarding facebook and / or twitter are never answered here. Try a
group or forum dedicated to these APIs.

-------------------------------------------------------------------------------------------------
TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago
transit tracking app for Android-powered devices

-- 

2. Relace Style.xml or Strings.xml

How can i replace the style.xml or strings.xml in the res/ directory
from the web, after the application is compiled and deployed.
Can i use a webservice, load this file from a URL and replace these
files, and still use."R....
are i  have to do this manually in my code to reset the styles....

-- 

3. Leveraging google account credentials to send emails in the background

4. PreferenceActivity interface question

5. Mirink Jogja Chapter EndYear 2010

6. CursorAdapter performance

7. Android Twitter client Storing in shared preference