Thursday, July 19, 2012

Where to put android app start-up initialization

There is no 'main' function in Android app. There is a main activity that get lunched when user clicks on app's icon, but other activities can be started as well. So, if the app need some setting up at start up, where should that be in. It turns out that you can have a main entry point that got called every time the program starts.  Simply put initialization code there and it's all good.

To use it, you have to create a new class that extends Within it you have to override onCrate method. This method will get called when app starts.
public class MyMainEntryPoint extends Application { 

    public void onCreate() {
        // init goes here
Then, in AndroidManifest.xml, you have to declare your entry point using android:name attribute under application tag



No comments:

Post a Comment