關於不推薦使用嵌套多於一個activity的解釋(用view代替)~~取自官方論壇

Nesting activities

BY Joan Pujol | Post Datetime: Wed, 27 Apr 2011 03:43:07 GMT | #1/12


                 I've read in that 
message<https://groups.google.com/d/topic/android-developers/3-GvDgnV6zk/discussion>
 that 
it was not possible to nest more than one activity. It's still true?
And if it's true what is the recommended workarround?
In my app I've a main TabView and I also need to have a flow inside the tab 
child activities. In the post I read that I can use simply view but if my 
program grows I doesn't found it practical.

A lot of thanks,

-- 
Re: Nesting activities
BY Mark Murphy | Reply DateTime: Wed, 27 Apr 2011 03:53:47 GMT | #2/12
Yes.


Not doing it.


In general, I do not recommend that. I do not even recommend having
activities as contents of tabs. TabHost and related classes are being
replaced with tabs in the action bar managing fragments.


You are welcome to use fragments, with the Android Compatibility
Library. You cannot use the action bar except on Android 3.0, at
present, unfortunately.

You are welcome to not "have a flow inside the tab child activities".
For that matter, you are welcome to get rid of the "child activities"
and replace them with views.

Or, you are welcome to organize your code in other ways. Please bear
in mind that object-oriented programming predated Android by decades,
and so you are welcome to organize your logic using your own non-View,
non-Activity classes if you desire.

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

Warescription: Three Android Books, Plus Updates, One Low Price!

-- 
Re: Nesting activities
BY Joan Pujol | Reply DateTime: Wed, 27 Apr 2011 04:11:09 GMT | #3/12
On Tuesday, April 26, 2011 9:53:10 PM UTC+2, Mark Murphy (a Commons Guy) 



Thanks Mark,

You are welcome to not "have a flow inside the tab child activities".
But then I've to organize all my application without activities, haven't I?
Because the solution with fragments, if I can't use the action bar can I use 
it combined with the TabActivity? 

Cheers,


-- 
Re: Nesting activities
BY Mark Murphy | Reply DateTime: Wed, 27 Apr 2011 04:22:29 GMT | #4/12
I am merely saying that the contents of your tabs do not need to be
activities and will not be activities once you start working with
Android 3.0.


I don't have a recipe for using fragments with TabActivity, sorry.

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

Warescription: Three Android Books, Plus Updates, One Low Price!

-- 
Re: Nesting activities
BY Joan Pujol | Reply DateTime: Wed, 27 Apr 2011 04:43:48 GMT | #5/12
A lot of thanks Mark,

On Tuesday, April 26, 2011 10:21:55 PM UTC+2, Mark Murphy (a Commons Guy) 


But if my main activity/view it's a tab then I have to organize all without 
activities. Or I'm missing something? 

I will try to investigate a little on that. Because it's the only good 
solution that I see by now. 

Cheers,


-- 
Re: Nesting activities
BY Mark Murphy | Reply DateTime: Wed, 27 Apr 2011 04:48:10 GMT | #6/12
It is impossible for your "main activity" -- the one implementing
ACTION_MAIN in the manifest -- to be inside of a tab.

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

Warescription: Three Android Books, Plus Updates, One Low Price!

-- 
Re: Nesting activities
BY Dianne Hackborn | Reply DateTime: Wed, 27 Apr 2011 05:01:57 GMT | #7/12
There isn't a recipe, because it doesn't make sense.  TabActivity is a
specialization of tabs for when they are being used to switch between
activities.  If you are using fragments, that is not what you want.
 Instead, just use a TabHost directly and when the user switches tabs,
switch your fragments.

-- 
Dianne Hackborn
Android framework engineer
[email protected]

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

-- 
Re: Nesting activities
BY Joan Pujol | Reply DateTime: Wed, 27 Apr 2011 05:15:55 GMT | #8/12
On Tuesday, April 26, 2011 10:47:37 PM UTC+2, Mark Murphy (a Commons Guy) 



No, it's not in the tab but it "it's the tab" that organizes all the 
application flow.

-- 
Re: Nesting activities
BY Joan Pujol | Reply DateTime: Wed, 27 Apr 2011 05:18:32 GMT | #9/12
Thanks Dianne,




Ok, I will try. Is that the best solution available for 2.0 compatibility to 
be able to have a TAB as main flow and also have child flows in some tabs?

Cheers,



-- 
Re: Nesting activities
BY Dianne Hackborn | Reply DateTime: Wed, 27 Apr 2011 08:13:05 GMT | #10/12
It is one of many ways to do it.









-- 
Dianne Hackborn
Android framework engineer
[email protected]

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

-- 
Re: Nesting activities
BY Joan Pujol | Reply DateTime: Wed, 27 Apr 2011 12:32:32 GMT | #11/12
Thanks Dianne,

One of the many?
Is there another simple alternative without using the compatibility kit and 
haven't to manage the lifecycle by hand ? Because if it were possible I 
would want to leave the application as similar as if it was possible to nest 
the activity groups.

Cheers,




-- 
Re: Nesting activities
BY Dianne Hackborn | Reply DateTime: Wed, 27 Apr 2011 12:43:02 GMT | #12/12
I just mean that the underlying tab control widget and the view hierarchy
are very generic facilities.  You can build a lot of things from them -- get
callbacks when the user clicks on tabs, create whatever different view
hierarchies you want to show for the tabs, etc.

It's not like the fragment support library is a magical piece of code.  It's
just normal code anyone can write on top of the SDK.  The most significant
thing about it is that it is almost exactly the same as similar code built
in to newer versions of the platform, so gives an easier transition path.








-- 
Dianne Hackborn
Android framework engineer
[email protected]

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章