Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Check now, I have updated the code.</p> <p>Here is the code for CountDownTimer. and when time completes it sends an notification. You can use it in Service or in a normal Activity.</p> <pre><code> public String ns = Context.NOTIFICATION_SERVICE; public NotificationManager mNotificationManager; Notification notification; PendingIntent contentIntent; Intent notificationIntent; public class Main extends Activity{ private final long startTime = 50000; private final long interval = 1000; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); int time=Integer.parseInt(editText.getText().toString()); time=time*1000; startTime = time; // place this code on button listener if you want. countDownTimer = new MyTimer(startTime, interval); } } public class MyTimer extends CountDownTimer { public MyTimer(long startTime, long interval) { super(startTime, interval); } @Override public void onFinish() { mNotificationManager = (NotificationManager) getSystemService(ns); notificationIntent = new Intent(this, MyActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); notification = new Notification(R.drawable.icon,"Time up..", System.currentTimeMillis()); notification.setLatestEventInfo(this, "CallingaCab", "YOUR TIME COMPLETED", contentIntent); mNotificationManager.notify(0, notification); startActivity(notificationIntent); } @Override public void onTick(long millisUntilFinished) { //Perform what do you want on each tick. } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload