• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Best practices separation of logic and UI

Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?

Posts: 1369
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
Would anybody like some fudge? I made it an hour ago. And it goes well with a tiny ad ...
a bit of art, as a gift, the permaculture playing cards
    Bookmark Topic Watch Topic
  • New Topic