android - Countdown Timer Notification -


i'm begginer in android programming, have countdowntimer starts number selected user using 2 number pickers (one hours , other minutes).

the characteristics must be:

-the countdowntimer must work in background , notify user when arrives 00:00. have code:

package com.android.application; import android.app.activity; import android.app.notification; import android.app.notificationmanager; import android.app.pendingintent; import android.content.intent; import android.os.bundle; import android.view.view; import android.widget.button; import android.widget.numberpicker;  public class mainactivity extends activity { notificationmanager nm; private static final int id_notificacion_personal =1;  @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main);  numberpicker number1 = (numberpicker)findviewbyid(r.id.horas); numberpicker number2 = (numberpicker)findviewbyid(r.id.minutos); button btn_lanzar=(button)findviewbyid(r.id.btn_notificacion); number1.setmaxvalue(10); number1.setminvalue(0); number2.setminvalue(0); number2.setmaxvalue(59);  int number3=number1.getvalue(); int number4=number2.getvalue();  nm = (notificationmanager)getsystemservice(notification_service); btn_lanzar.setonclicklistener(new view.onclicklistener(){     @override      public void onclick(view v) {     notification notification = new notification(r.drawable.estacionamiento,"estacionamiento inteligente",system.currenttimemillis());         pendingintent intencionpendiente = pendingintent.getactivity(getapplicationcontext(),0, new intent (getapplicationcontext(),segunda_ventana.class),0);     notification.setlatesteventinfo(getapplicationcontext(), "estacionamiento inteligente", "su tiempo se ha terminado", intencionpendiente);     nm.notify(id_notificacion_personal, notification);     }  }); }  }  

i don't know how make countdowntimer begins number selected user number pickers , notification when done.

please me. :(

use android's timer , timertask classes. below assume know how display notifications, appears in question.

along number pickers, have button defined in static layout so:

<button     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="start countdown"     android:onclick="startcountdown"  /> 

above assume have number pickers in same layout.

java activity code might follows:

numberpicker hourpicker; numberpicker minutepicker;  @override protected void oncreate(bundle savedinstancestate) {     hourpicker = (numberpicker)findviewbyid(r.id.horas);     minutepicker = (numberpicker)findviewbyid(r.id.minutos);     hourpicker.setmaxvalue(10);     hourpicker.setminvalue(0);     minutepicker.setminvalue(0);     minutepicker.setmaxvalue(59); }  public void startcountdown(view v) {     //this fires when button tapped     showtimerstartednotification();      int hours = hourpicker.getvalue();     int mins = minutepicker.getvalue();      int millis = ((hours*60)+mins)*60000; // need milliseconds use timer       new timer().schedule(new timertask()     {         @override         public void run()         {             //code runs when timer done             showtimerfinishednotification();         }     }, millis); } 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -