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;
}
}