I want to make a foreground service that calls an Asynchrounic task every few seconds. so I defined a foreground service like this:(I haven't added the task yet)
import android.app.Notification;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat;
import static com.example.notif.App.ID;
public class Service extends android.app.Service {
    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }
    @Override
    public void onCreate() {
        super.onCreate();
    }
    @Override
    public void onDestroy() {
        super.onDestroy();
    }
    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Intent notificationIntent= new Intent(this, MainActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this,0,notificationIntent,0);
        Notification notification = new NotificationCompat.Builder(this,ID)
                .setContentTitle("Title")
                .setContentText("Text")
                .setSmallIcon(R.drawable.ic_android)
                .setContentIntent(pendingIntent)
                .build();
        startForeground(2,notification);
        return START_STICKY;
    }
}
edited the manifest like this and added the service to it.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.notif">
    <uses-permission android:name="android.permission.INTERNET"></uses-permission>
    <application
        android:name=".App"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:usesCleartextTraffic="true"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.Notif">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <service android:name=".Service"></service> //i added service here
    </application>
</manifest>
and I start it with an onClickListener:
public void start(View view) {
        Intent serviceIntent = new Intent(this,Service.class);
        startService(serviceIntent);
    }
when I press the button the app crashes. what am I doing wrong? how should I proceed?
 
     
    