Vote count:
0
I have a service that performs an operation after a certain delay. I want to show a notification when the service is started, and when the notification is clicked it cancels the operation. No UI, all done in the background. The service is started on boot by a broadcast receiver.
Also ideally I want to update the notification every 1 sec to show the remaining time.
... start operation thread and call thread.sleep(delay)
... create notification builder (nBuilder)
try { // example assume delay = 30 seconds
for (int sec = 30; sec >= 0; --sec) {
nBuilder.setContentText("Applying settings in " + sec + ", Click to cancel");
mNotifyMgr.notify(0x01, nBuilder.build());
Thread.sleep(1000);
}
}
catch (InterruptedException e) {
e.printStackTrace();
}
how can I break this loop when the notification is clicked? This code is in my service. As far as i know the only way to respond to click is to set a pending intent, but how can I use this intent to break the loop and cancel the operation in my service?
Thanks for reading
asked 42 secs ago
Android notifications get service that started the notification?
Aucun commentaire:
Enregistrer un commentaire