Notification in Service on isolated process throws NPE

591 views Asked by At

I get a NullPointer, every time I try to send a Notification from a service that runs on a isolted service.

The exception:

    java.lang.NullPointerException
        at android.app.NotificationManager.notify(NotificationManager.java:136)
        at android.app.NotificationManager.notify(NotificationManager.java:109)
        at de.nwo.client.modules.service.NwoService.createOrUpdateNotification(NwoService.java:66)
        at de.nwo.client.modules.service.NwoService.access$000(NwoService.java:23)
        at de.nwo.client.modules.service.NwoService$1.run(NwoService.java:47)
        at android.os.Handler.handleCallback(Handler.java:730)
        at android.os.Handler.dispatchMessage(Handler.java:92)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:5103)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:525)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
        at dalvik.system.NativeStart.main(Native Method)

Manifest declaration:

        <service
        android:name=".modules.service.NwoService"
        android:exported="false"
        android:isolatedProcess="true"
        android:process=":nwoService"/>

The service implementation:

    @Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.d(SERVICE_TAG,"started!");
    startLogging();
    return Service.START_STICKY;
}

private void startLogging() {
    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            createOrUpdateNotification();
            startLogging();
        }
    },3000);
}

private void createOrUpdateNotification(){
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder
            .setSmallIcon(R.mipmap.ic_launcher)
            .setPriority(Notification.PRIORITY_MAX)
            .setColor(Color.GREEN)
            .setOngoing(true)
            .setContentText(String.valueOf(++increment))
            .setContentTitle("NWO");
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    Notification f = builder.build();
    Log.d(SERVICE_TAG, "nm: " + mNotificationManager + " , notification: " + f);
    mNotificationManager.notify(notificationID, f); //npe here
}

If I remove the lines android:isolatedProcess="true" and android:process=":nwoService" from the manfiset, everything works like intended. Does anybody know the reason? Why can't I use the NotificationManager from an isolated process?

0

There are 0 answers