fsnasser
fsnasser

Reputation: 203

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!

Upvotes: 3

Views: 2952

Answers (3)

Pavel Pashanov
Pavel Pashanov

Reputation: 1

This worked for me - try using this property in your Manifest file:

<application 
android:name=".SomeApplication"
android:usesCleartextTraffic="true"

Upvotes: 0

Ivan
Ivan

Reputation: 1444

In my case I forgot about declaration in the manifest:

<application 
    android:name=".App" 
...>

Upvotes: 1

muthuraj
muthuraj

Reputation: 1102

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.

Upvotes: 12

Related Questions