Java : Package specific static initialization

       I was working on a sample android application having an activity and a service, declared in the same package. The application logic didn't enforce a specific order of creation and had to perform static initialization irrespective of whichever application component was created first by android framework (which ever class was loaded by the DEX class loader of dalvik virtual machine). This basically boils down to a Java package level static initialization and i had to settle for a workaround using singleton pattern




Init enforces a singleton pattern and exposes a static function (initialize) invoked by the static blocks of both Activity and Service.





No comments: