关于不推荐使用嵌套多于一个activity的解释(用view代替)~~取自官方论坛
2011-12-16 13:58
537 查看
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 hack...@android.com 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 hack...@android.com 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 hack...@android.com 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.
相关文章推荐
- 关于Android7.0系统使用webview遇到的一个问题(二级跳转后界面空白)
- 无废话Android之smartimageview使用、android多线程下载、显式意图激活另外一个activity,检查网络是否可用定位到网络的位置、隐式意图激活另外一个activity、隐式意图的配置,自定义隐式意图、在不同activity之间数据传递(5)
- 关于ViewPager嵌套Fragment,Fragment使用GridView导致的问题
- 在一个Activity中使用多个View (可以借鉴的一种思路)
- Android 使用setContentView在一个Activity进行界面切换
- 5.0及以上系统上使用CircleImageView圆形头像出现方块背景问题(上一个Activity中的页面)
- UI基础第十四弹:实现UItableview使用嵌套模型完成的一个简单汽车图标展示程序
- android------使用TextView链接打开一个Activity
- Android中关于RecycleView的使用,代替ListView,可以提高效率
- 关于ViewPager Activity的一个问题
- 论坛短信中一个关于ADOMD使用的答复。
- 论坛源码推荐(10.22):使用iOS8 WKWebView的浏览器模块,脉冲动画层
- 关于WebView的使用js和java的相互调用(包含按返回按钮时,返回上一页而不是推出activity)
- 关于Recyclerview使用时的一个错误java.lang.NoSuchMethodError: No static method getMatrix(Landroid/view/View;)
- 关于Recyclerview使用时的一个错误
- 关于scrollview嵌套listview的方法。但官方并不推荐这种做法。
- 2017-6-14 关于使用history.go的问题!配合原生应用嵌入H5页面(只有一个webview的的单页应用)返回历史列表记录的问题
- 关于Loader,activity,Fragment之间的一个使用
- 推荐一个UIAlertView的第三方扩展,可以大大简化UIAlertView的使用
- 关于Recyclerview使用时的一个错误java.lang.NoSuchMethodError: No static method getMatrix(Landroid/view/View;)