作出这样的Andr​​oid应用程序向导向导、应用程序、Andr、oid

2023-09-12 06:12:55 作者:也许べ已没有也许

你觉得是做一个像精灵应用程序的最佳方法(用户与下一个和后退按钮屏幕之间可以浏览,每个屏幕有保存一些状态数据)的Andr​​oid平台。

Which you think is the best way of doing a wizard like application (user can navigate between screens with a next and back button, and each screen has to save some state data) in Android platform.

我主要可以通过两种方式思考:

I mainly can think in two approaches:

有一个活动+查看每个屏幕,然后我使画面​​切换调用各项活动。是什么让这个漂亮的是,我可以使用系统恢复按钮,我的背部处理程序,我不都采取了照顾自己后也每项活动都会保存自己的状态。

Having one activity+view for each screen and then i make the screen switch by calling each activity. What make this nice is that i can use the system back button as my back handler and i don't have to take care of that myself, aslo each activity will save it's own state.

有一个活动,很多意见,我切换视图中的每个画面切换,这可以帮助我重新使用更多的code,但使节能状态一塌糊涂。

Having one activity and many views, and what i switch views in each screen change, this helps me re-use more code, but makes saving states a mess.

你怎么看?这是在Android这样做的最好的方法是什么?

What do you think? Which is the best way of doing this on Android?

推荐答案

我建议将与2,因为它适合的活动和观点的目的。在这种情况下,保存状态是很容易 - 如果你使用MVC模式,你可以简单地有沿的意见传递模型对象。每个视图将具有它可以读/写的模型的部分。无论您身在何处,该模型应该总是有当前状态。如果你被处理,只是保存模型。既然你已经从模型看,当你表现出的每一页自动恢复工作。

I suggest going with 2 as it fits the goal of activities and views. Saving state in this case is easy - if you use the MVC pattern, you can simply have a model object that is passed along to the views. Each view will have portions of the model that it can read/write. No matter where you are, the model should always have the current state. If you get disposed, just save the model. Restore works automatically since you already read from the model when you show each page.