开发者

Managing an Activity with many states

I have an activity that has possibly many different states.

For example

  • no internet
  • no license
  • logged in
  • not logged in
  • pending
  • error
  • restricted
  • deprecated

At the moment I have if statements that determine the appropriate state of the application and enable or disable views as required. I was thinking that some sore of STATE pattern might be better.

Can someone give me some idea of how I might do this with an Activity like this? Or in this case is an if statement like this a better option as the views are开发者_StackOverflow tightly coupled to the Activity anyway.


I wouldn't disable the views for some of thise things ie no internet. Just let the user try to interact and give relevant error messages.

A good rule of thumb is that if you're changing the views significantly from one state to the other, maybe it should be a different activity? There should be very little reason to change the LAYOUT of views based on state.


This question is as old as the internet now, but the OP should really check out Stateless4J.

It provides lightweight Finite State Machines with easy syntax. I use it in all my Java projects.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜