i have intentservice associate with geofence. service is called a notification send and inside service their is a thread which update the notification after 10 sec.
here is code:
@Override
protected void onHandleIntent(Intent intent) {
sendNotification("enter",2);
t=new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(10000);
sendNotification("PICK",2);
}
catch (Exception e)
{
Log.e("ERROR",e.toString());
}
}
});
t.start();
}
here is send notification code
private void sendNotification(String notificationDetails,String itineraryID) {
// Create an explicit content Intent that starts the main Activity.
Intent notificationIntent = new Intent(getApplicationContext(), Detail.class);
notificationIntent.putExtra("ID",ItineraryID);
// Construct a task stack.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
// Add the main Activity to the task stack as the parent.
stackBuilder.addParentStack(Detail.class);
// Push the content Intent onto the stack.
stackBuilder.addNextIntent(notificationIntent);
// Get a PendingIntent containing the entire back stack.
PendingIntent notificationPendingIntent =
stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
// Get a notification builder that's compatible with platform versions >= 4
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
// Define the notification settings.
builder.setSmallIcon(R.drawable.to_chegando_icon)
// In a real app, you may want to use a library like Volley
// to decode the Bitmap.
.setLargeIcon(BitmapFactory.decodeResource(getResources(),
R.drawable.to_chegando_icon))
.setColor(Color.RED)
.setContentTitle("Saida da Escola"+ itineraryID)
.setContentText(notificationDetails)
.setContentIntent(notificationPendingIntent);
// Dismiss notification once the user touches it.
builder.setAutoCancel(true);
// Get an instance of the Notification manager
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// Issue the notification
int n=Integer.parseInt(itineraryID);
mNotificationManager.notify(n, builder.build());
}`
this work fine create notification and update it after 10 second.
the problem is when i create a notification and then kill the app from background(press home button and then kill app from background apps) then this thread doesnot update the notification. why is that ??? any solution