custom android.app.Application not firing onCreate event

Viewed 21702

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();
7 Answers

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.

In Manifest file Make sure u have added the tag i.e class which extends Application.

Tag= android:name=".MyApplication

ManifestFile

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.services">
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <application
        android:name=".MyApplication"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.Services">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <!--Declaring the Service in the manifest file-->
        <service
            android:name=".MyServiceDemo"
            android:foregroundServiceType="dataSync" />
    </application>
</manifest>

MyApplication.java(i.e class which extends Applicatoin)

package com.example.services;

import android.app.Application;

public class MyApplication extends Application {

    private static MyAppsNotificationManager notificationManager;

    @Override
    public void onCreate() {
        super.onCreate();
        notificationManager = MyAppsNotificationManager.getInstance(this);
        notificationManager.registerNotificationChannelChannel(
                getString(R.string.channelId),
                "BackgroundService",
                "BackgroundService");
    }

    public static MyAppsNotificationManager getMyAppsNotificationManager(){
        return notificationManager;
    }
}
Related