如何在一个App内实现多屏
我目前正在开发一个Android应用程序,它具有不同的服务维度,例如“服务订单”,“路线规划”,“照片库”和中央登录。 到目前为止,我将每个“屏幕”(屏幕实际上是屏幕的布局)实现为一个单独的类,它加载特定的布局并处理所有侦听器和核心功能,例如在线程中调用 Web 服务、接收答案等。 我不太确定这是否是实现多个布局屏幕的最佳方式。
Android 开发指南建议为每个“屏幕布局”使用单个活动。但我怀疑这是最有效的做事方式。因为我需要由中央登录(此处:用户对象)检索的每个“布局”的信息。由于活动(据我所知)是一个单独的线程,因此信息的传递和检索似乎不太实用。
我想得到您对此的意见/反馈,并感谢您的任何提示或提示。
到目前为止,我的结构如下:
- Activity
- 加载登录布局(带有 setlContentView 的 res/layout/login.xml)
- 根据按钮单击其他资源的加载和初始化(意味着添加侦听器等)
。 彼得
I am currently working on an Android App which has different service dimensions, such as " service order", "route planning", "photo gallery" and a central login.
so far i implemented each "screen" (and by screen i mean actually the layout of a screen) as a seperate class, which loads a specific layout and handles all listeners and core functionalities such as calling webservices in a thread, receiving answers etc.
I am not quite sure if this is the best way to implemnt mulitiple layout-screens.
The Android dev guideline proposes to use single activities for each "screen layout". However I doubt that this is the most effective way of doing things. Since i need information for each "layout" which are retrieved by the central login (here: a user object). Since an activity (as far as i understand) is a seperate thread, the passing and retrieving of information seems not very practical.
I would like to get your oppinions/feedback on that and thanks for any hint or tip.
So far my structure looks like :
- Activity
- loads login layout (res/layout/login.xml with setlContentView)
- depending on buttonclick other resources are loaded and initialized (means listeners are added etc.)
Greets
Peter
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
开发指南建议这样做是有原因的。这是最有效的做事方式。您可能会抱怨必须存储数据以便可以在活动之间传递数据,但你猜怎么着?您正在开发手机应用程序!在任何时候,电话都可能响起,迫使用户离开您的应用程序。或者用户可以选择暂时查看不同的应用程序。如果您的应用程序在切换回来并丢失所有数据后返回到第一个位置,那么用户会感到愤怒,这是可以理解的。
The dev guidelines recommend that for a reason. It IS the most effective way of doing things. You may complain about having to store your data so it can be passed along from activity to activity, but guess what? You're developing an app for a phone! At any point in time, the phone could ring, forcing the user to switch away from your app. Or the user could just choose to temporarily look at a different app. If your app goes back to square one after switching back and lost all data, the user will be understandably angry.
不知道这是否适合您的应用程序,但另一种选择可能是将核心数据处理拆分为服务,并让您的应用程序只是与该服务通信的 UI 前端。
Don't know if this would be suitable for your app, but another option could be to split off the core data handling into a Service, and have your app be just a UI frontend which communicates with that service.