Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

custom android.app.Application not firing onCreate event

I'm deriving a custom application from android.app.Application and I can't get its onCreate event being fired. Here's the implementation

import android.app.Application;  public class MyApplication extends Application {      public MyApplication() {         super();     }      @Override     public void onCreate() {         super.onCreate();     } } 

And here's how I'm using it:

MyApplication ctrl = new MyApplication(); 
like image 743
Narcís Calvet Avatar asked Jul 28 '11 11:07

Narcís Calvet


People also ask

Why do we need to call setContentView () in onCreate () of activity class?

onCreate() method calls the setContentView() method to set the view corresponding to the activity. By default in any android application, setContentView point to activity_main. xml file, which is the layout file corresponding to MainActivity.

What is the purpose of onCreate () function in Android?

onCreate(savedInstanceState); calls the method in the superclass and saved InstanceState of the activity if any thing damage the activity so its saved in instanceState so when reload the activity it will be the same before.

What is it called when an application is onCreate?

Note that if any service is defined to run in other process e.g. with android:process= then Application's onCreate() will be called again for that process.


2 Answers

Add following in your AndroidManifest.xml

<application     android:name="MyApplication"     android:debuggable="true"     android:icon="@drawable/icon"     android:label="@string/app_name"> </application> 

then your onCreate() will get fired.

like image 122
Balaji Khadake Avatar answered Sep 30 '22 11:09

Balaji Khadake


I had this issue and found that in my case that the whole issue was phone side. I rebooted the phone and that fixed the issue.

like image 29
Brad Avatar answered Sep 30 '22 10:09

Brad