G
G
GadZini2014-06-14 16:47:25
Java
GadZini, 2014-06-14 16:47:25

Why is the notification coming early?

private Runnable Timer = new Runnable() {
@Override
public void run() {
try {
Thread.sleep(1000);
} catch (Throwable t) {
}
};
};
Based on this thread, I created a kind of timer
while (LAST_MILLI_SEC != 0);{
new Thread(Timer).start();
String t = String.valueOf((LAST_MILLI_SEC/1000)-1);
Toast.makeText(this, t,Toast.LENGTH_LONG).show();//After every sec. sleep outputs the message
LAST_MILLI_SEC = LAST_MILLI_SEC - 1000;//Then subtracts 1 second from the remaining time
if(LAST_MILLI_SEC/1000 == 0){
//Here, the timer must first count down to zero, and only then send a notification?????
Notification notification = new Notification();
Context context = getApplicationContext();
Intent notificationIntent = new Intent(context, MainActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(context, 0,
notificationIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
long[] vibrate = new long[] {1000, 1000, 1000, 1000, 1000};
notificationIntent.putExtra("url", "dtrek.dp.ua");
Notification.Builder builder = new Notification.Builder(context)
.setContentTitle("Look at the replacements")
.setTicker("Warning!") // java.lang.System.currentTimeMillis()
.setContentIntent(pIntent)
.setDefaults(Notification.DEFAULT_SOUND).setAutoCancel(true)
.setSmallIcon(R.drawable.ic_launcher);
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(NOTIFY_ID, builder.build());
notification.vibrate = vibrate;
notification.flags = notification.flags | Notification.FLAG_INSISTENT; }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2014-06-18
@itvdonsk

Does it arrive before what time?
It does not output after a second of sleep, but after the thread has started. Which, by the way, does nothing, "sleeps" for a second and ends.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question