Android,项目和活动生命周期中的活动数量不受限制!
几天前,我在 Android Marketplace 中发布了我的应用程序,在设计和开发应用程序时我想到了一个问题。这个问题是关于活动数量的限制或无限。
例如,我的应用程序包括 37 个活动。有这么多吗?我想知道像《愤怒的小鸟》这样200多个关卡的游戏,它有200个活动吗?!!
我的下一个问题是,假设我正在设计一个包含 100 个活动的应用程序。用户启动应用程序并进入上一个活动(例如读书)。如果用户想关闭应用程序该怎么办?在他的设备上按返回键 100 次?! 如果我想在选项菜单中放置关闭按钮(以帮助用户),我是否必须为每个活动重复它?因为据我所知,每个活动都有自己的菜单。
如果我在上一个活动中放置关闭按钮并且用户单击它,程序将关闭。其他99活动会怎样?它们还存在于堆栈中吗?或者当我关闭应用程序时,与该包相关的所有活动都将从堆栈中删除。
我已阅读 Android 发布的活动页面,但找不到我的答案。
抱歉,如果以上问题是愚蠢的问题:) 谢谢
Some days ago I have published my application in Android Marketplace and a question came into my mind during designing and developing application. This question is about limitation or unlimitation of number of activities.
For example, my application includes 37 activities. Is it so much? I want to know for a game such as "Angry Birds" which has more than 200 levels, it has 200 activities?!!
My next question is, assume that I am designing an application which includes 100 activities. User starts application and gos into last activity (such as reading a book). If user wants to close the application what should he do? 100 times press back key on his devise?!
If I want to put close button(to help user) in options menu, do I have to repeat it for each activity? because as far as I know each activity has its own menu.
If i put close button in last activity and user clicks on it, program will close. What will happen to other 99 activities? are they still exist in stack? or When I close an application, all activities related to that package will delete from stack.
I have read activities page published by Android but I couldn't find my answers.
Sorry if above questions are stupid questions :)
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
就 Anry Bairds 而言,我怀疑他们是否有数百个活动,我认为他们只有一个(或可能是几个)用于级别,另一个用于欢迎屏幕 - 可能会根据传递给的某些参数加载不同的级别。活动。
至于如何处理100个加载的Activity,首先,系统很可能会在你到达第100个Activity之前回收堆栈底部的旧活动。如果没有,那么是的,您的用户将必须点击返回 100 个活动。
如果你想改变后退按钮的行为,你可以重写 onKeyDown()。
或者,如果您想更改活动启动方式的默认行为,请查看 活动启动模式。
In the case of Anry Bairds, I doubt they have 100s of activities, I think they just have one (or possibly a couple) for levels and another for the welcome screen - different levels are probably loaded depending on some parameter that was passed to the activity.
As for how to handle 100s of loaded activities, first of all, it is very likely that the system will recycle the old ones at the bottom of the stack before you get to the 100th activity. If not, then yes, your user will have to click back through a 100 activities.
If you want to change the behaviour of what the back button, you can override onKeyDown().
Or if you want to change the default behaviour of how activities are launched, then take a look at activities launch mode.
请阅读任务和返回堆栈和活动和任务设计指南
Please read Tasks and Back Stack and Activity and Task Design Guidelines
嗯,首先,关于愤怒的小鸟,我猜它几乎完全是用 OpenGL ES 编写的,因此它只包含几个活动。
其次,如果您确实有 200 个活动,您可能应该考虑一个可以多次重复使用的活动。例如,如果每一页都应该具有相同的外观和功能,为什么您需要为一本书的每一页进行一个活动?只需用额外的数据激发一个意图,它就应该可以工作。而且,要关闭应用程序,您只需按主页按钮即可:-)
Well, first, regarding angrybirds, I guess it is written nearly entirely in OpenGL ES, so it consists of only a few activities.
And second, if you're really having 200 activities, you should probably think of an activity which can be reused multiple times. e.g. why would you need one activity for every page of a book, if every page should have the same look and functions? Just fire an intent with extra data and it should work. And, to close the app, you can simply press the home button :-)
像《愤怒的小鸟》这样的应用程序可能有一个带有 OpenGL ES 视图的活动,所有的接口都是通过相对布局完成的
,也就是说,您可以拥有无限数量的活动,唯一关心的是您的应用程序将占用多少空间,为什么任何用户都希望在他们的移动设备上浏览如此强大的程序,以及您使用了多少 RAM 以及您是否有效地管理您的活动
An application like Angry Birds probably has one activity with an OpenGL ES view, with all of the interfacing done with a RelativeLayout
that being said, you could have an unlimited number of activities, the only concern is how much space your app will take, why any user would want to navigate through such a robust program on their mobile device, and how much RAM you are using and are you managing your activities efficiently