3

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.

3 Answers 3

4

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

Sign up to request clarification or add additional context in comments.

Comments

0

You are calling the notify of the Java Object class:

http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html

2 Comments

So what exactly does that mean?
It means you are doing "Wakes up a single thread that is waiting on this object's monitor" which has absolutely nothing to with Android Notifications.
0

Wrong notify() method.

 NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); notificationManager.notify(0, CreateNotification()); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.