- It's easy to use transparent PNG graphics inside a SurfaceView so long as you clear your bitmaps with the eraseColor(android.graphics.Color.TRANSPARENT) instead of filling your bitmap with white. Took me three days to figure that out.
- The word 'Activity' in Android is almost synonymous with screen or process. Think of each functioning element in your program as individual Activities. So, if you're making a database program, you could have an activity for the screen where you add records and another activity for the screen for modifying records. If it's a game: one activity for the main menu, another for settings, one for the high score table, and another for the main game itself…
- Learn about 'context'. I think it's the single most confusing and difficult element of the Android API. I'm not entirely sure what it is myself and I'm still not entirely sure how to 'get' it from different points in the code.
- Learn to nest layouts right at the start. Setting up screens is a nightmare until you understand that you can, for example, drag a horizontal layout onto the screen and embed elements inside that. That layout can then be dragged into a vertical layout, making it really easy to arrange elements both vertically and horizontally on the screen.
- Don't go looking for 'file open' dialogs. They don't exist natively in Android and, to be honest, I'm not entirely sure they are needed. It's really easy to throw data out to other apps, such as email, Evernote and Dropbox.
- Be quite liberal debugging with Log.d("Activity1", "Loop7"). As your app runs, it throws up messages to a console on your PC so you can track the code and see where it stops, throws errors or is trapped in loops.
- Saving preferences inside your app is unbelievably easy with the SharedPreferences object.
Saturday, March 15, 2014
Programming Android: Three Weeks On
As much as I hate to admit it, I think I've finished my app. It's a proper monstrosity of bad design, hastily drawn graphics and butchered code but in the space of less than a month I've gone from not knowing a thing about the Android SDK to being in the final stages of testing a functioning app that does everything I originally intended plus a little bit more. Three weeks ago I began this adventure by thinking: I wish I could find an app that does X,Y, and Z. Now I have an app that does X,Y, and quite a bit of the Z and it has probably saved me 69p had this app originally existed in the Play Store. I can't say that it's been an easy three weeks and I'm not sure I would have liked to have attempted this without some programming experience. Yet, had I been learning from scratch, I'm not sure Android is the worst place to begin to learning to program. It's certainly a friendlier developing environment than some I used when I started out many years ago. I remember the misery of coding on an old Vax in a cold university basement room when we all had to wear mittens to stop our fingers from freezing. And people wonder why it's taken me so long to come back to software engineering… Although I'm not exactly a new code monkey, I began not really knowing much Java and I'm not entirely comfortable with it now since it's clearly a language that's easy to learn but difficult to master. At a few points, I wanted to add features which just proved beyond my skillset. One required me to catch, buffer and then process MotionEvents (the data generated when the user touches the screen) but it led to a wasted two days and my utter defeat. Perhaps I'll try again with my next app... Things I know now but wish I'd known back then:
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment