Felipe Saran Nasser Felipe Saran Nasser - 17 days ago 6
Android Question

Custom Application class onCreate() never called

I'm trying to initialize Parse on a custom Application class:

import android.app.Application;
import android.util.Log;

import com.parse.Parse;
import com.parse.ParseException;
import com.parse.ParseInstallation;
import com.parse.SaveCallback;

public class SomeApplication extends Application {

@Override
public void onCreate() {
super.onCreate();
initializeParse();
}

private void initializeParse() {
Parse.setLogLevel(Parse.LOG_LEVEL_VERBOSE);
Parse.initialize(new Parse.Configuration.Builder(this)
.applicationId("##########")
.clientKey("############")
.server("https://#####.com/parse/")
.build()
);
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
installation.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
// Do something here
}
});
}

}


And I already declare this Application in AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.someproject">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".SomeApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".AnotherActivity"/>
</application>

</manifest>


But my custom Application is never called. I tried to put logs and break points on onCreate method, clean project, rebuild project, close and re-open Android Studio, uninstall and reinstall the app and nothing ... so, I need help.

Thanks!

Answer

Disable Instant Run, Clean build, Rebuild the project and then run again. I had the same issue. Disabling instant run worked for me. It is weird Application class not getting called. But it happened.

Comments