Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Notify causes object not locked by thread before notify()

I am trying to start up notification in background service which is also Location Listener. I have a function:

public Notification CreateNotification(){


        Intent notificationIntentStop = new Intent(this.getApplicationContext(), StopService.class);
        PendingIntent contentIntentStop = PendingIntent.getActivity(this.getApplicationContext(), 0, notificationIntentStop, 0);


        Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.logo);
        Shortcuts shorts = new Shortcuts(this);
        NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.logo)
                .setContentTitle("Localarm Running")
                .setLargeIcon(largeIcon);
        mBuilder.addAction(R.drawable.ico, "Stop", contentIntentStop);
        mBuilder.setContentText("Awake Me Up running.");
        mBuilder.setPriority(Notification.PRIORITY_MAX);
        Notification bui = mBuilder.build();

        bui.flags|= Notification.FLAG_NO_CLEAR;
            Intent notificationIntent = new Intent(this.getApplicationContext(), Intro.class);
            PendingIntent contentIntent = PendingIntent.getActivity(this.getApplicationContext(), 0, notificationIntent, 0);
            bui.contentIntent = contentIntent;

        return bui;
    }

And in onStart I call:

createNotification.notify();

However I get the following error:

"object not locked by thread before notify()"

how do I fix this? It literally needs to be called once and just keep running.

like image 893
arleitiss Avatar asked Feb 04 '26 10:02

arleitiss


1 Answers

notify and wait are two java methods that used in concurrency, in order to use android notification you must call

Notification noti = CreateNotification();

    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    noti.flags |= Notification.FLAG_AUTO_CANCEL;

    notificationManager.notify(0, noti);

for more references look at http://www.vogella.com/tutorials/AndroidNotifications/article.html

like image 133
mmlooloo Avatar answered Feb 06 '26 23:02

mmlooloo