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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With