Reputation: 505
I'm running a Handler to show some notifications in the background. While testing, when I set the delay limit to 5 seconds it works perfectly. But whenever I set it to 60 seconds or more it doesn't work. Why is that?
int delay = 1000 * 60;
HandlerThread hThread = new HandlerThread("HandlerThread");
hThread.start();
Handler handler = new Handler(hThread.getLooper());
Runnable task = new Runnable() {
@Override
public void run() {
NotificationManager manager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
Intent launchIntent = new Intent(getApplicationContext(), AndroidLauncher.class);
PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, launchIntent, 0);
NotificationCompat.Builder builder = new NotificationCompat.Builder(AndroidLauncher.this);
//Set notification information
builder.setSmallIcon(R.drawable.ic_launcher)
.setTicker("Hi!")
.setWhen(System.currentTimeMillis())
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_SOUND)
.setContentTitle(mytitle)
.setContentText(mytext)
.setContentIntent(contentIntent);
NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle(builder);
style.setSummaryText("4 Task");
style.addLine("Two");
style.addLine("Three");
style.addLine("Four");
style.addLine("Five");
Notification note = style.build();
manager.notify(50, note);
}
};
handler.postDelayed(task, delay);
Upvotes: 1
Views: 676