… 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

Did you read the page describing activity lifecycle?
Comment by Neil — May 9, 2010 @ 9:51 am
I did when I first started developing apps and never had any problem. But yesterday, after a few weeks of Java programming, I was in the habit of using a constructor to initialise my instances. As it happens, one of them needed to grab info from a xml file I had saved as a resource in the “res” folder.
It is surprising to me that you cannot access such resources from the constructor, because those files have nothing to do with the actual Activity, they are connected to the Application (indeed, they are accessible from all your Activities inside the Application). Hence my confusion.. this isn’t an obvious case, we’re not talking about Activity specific information related to the lifecycle here.
I understand that it’s to do with the “Context” only being defined for an Activity (hence only been defined once Activity is create via onCreate()) and not existing for an Application, which I think is a flaw.
Comment by Nat — May 9, 2010 @ 11:30 am