Cogitas Blog:
Google Android,
Common Lisp,
programming
and web design.

Constructors for Activity classes in Google Android…

Filed under: google android — Tags: , , — May 8, 2010

… are a big no-no.

I’ve just wasted about half an hour wondering why “context.getResources()” wasn’t working because I was calling it in the constructor of my activity class. It appears that Android actually needs to get through the onCreate() method to be able to access all the application data.

From now on, I know that I should never initialise my Activity class through a constructor but instead, always, always create a “initialise()” method which I call from the onCreate() method.

Android is great – I just wish it was better documented sometimes, but their doc is improving so it’s all good :-)