Wednesday, November 26, 2014

Android API First Impressions

I've recently finished my game and have started porting some of the Android only sections back to JavaSE. I have been struck by how everything seems so much easier with the Android API.

I find this very surprisingly. I've been using Swing for a very long time and have gotten good at doing crazy things with it. Even with my knowledge of Swing tricks and hacks it's still easier to do things on Android than Swing.

Take, for example, layouts. I've gotten to the point with Swing where I just use GridBagLayout from the start. I've got my own utilities that makes using GridBagLayout much less painful than it ordinarily would be. Gridbag is surprisingly flexible, if you've managed to survive its brutal learning curve. That said, doing layout with Android's isn't too bad. I certainly didn't have the parade of WTF moments that I experienced trying to wrap my head around Swing's layout system. Android also has the advantage of coming with a GUI layout editor. It means you don't find yourself blindly changing values and recompiling/relaunching every time to see if the changes did anything.

Then there are things like how do you make all the widgets translucent with an animated background? With Swing, I had to use the arcane knowledge I've discovered in my 10 years or so working with it. With Android it's just a property on the view or layout. Golly, that's convenient.

What about have multiple layouts on the screen at the same time and showing/hiding them like cards? With Android it's that way by default. With Swing it's a weird system of content panel layers or you can use CardLayout. Either way it's which is full of the usual Swing WTF moments: I have to do that to show a "card"? JLayeredPane is where?

Events are handled nicely too but to be honest, I was hoping for more here. Swing's event system is actually not too bad. Android's is very similar but also offers additional flexibility: you can define your event handler method directly in the layout. This is cute but this won't scale well if you have a fairly complex Application. That pretty much sums up my feelings towards Android event handling: It's good and tries to make things really convenience but the convenience comes at the price of preferring and unscalable application architecture.

Well, I say that but Android's encourages an application architecture that segments large applications into multiple activities which would help with scalability a great deal. I don't know how these two conflicting factors work out in real applications but I'm certain that either way there's more than enough flexibility in the approaches you can take to make everything work.

So, in conclusion, my experience with Android's APIs has been quite positive so far. I'm looking forward to more.

1 comment:

Randy Ford said...

Thank you for sharing. Useful for me the post, I'll try it. I often have questions to the technical part of my business, I use the services of this company https://jitbit.com/ they solve these problems. Once they have solved the problem in my personal project, not asking anything for it. I advise everyone to use the services of a professional contractor. Good luck.