Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Best practices separation of logic and UI

 
Joshua Elkino
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm in the middle of developing my first app while i learn dev for Android. I chose to do a simple game but i'm looking for some guidance.

I have a firm understanding on Activities and Views, but i'm unsure what the best approach is in placing my code.

I have created a custom view called BoardView that will generate the background, initialize my game pieces that are bitmaps, implement the drag and drop features, and so on. Currently my activity is only creating the view.
I have actually created the logic of the game in a basic console java app but i'm unsure of where to to put this logic.

Should i initialize all my global values in the Activity and pass them to the View? Should i make them static?
Does anyone have any suggestions and best practices?

Thanks!
 
Monu Tripathi
Rancher
Posts: 1369
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can have your view inside the Activity as an inner class, that way the view class will have access to all the state of the activity. Alternatively, you can also pass your activity context to the view class and then using this reference perform a get/set on the state of the Activity.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic