I'm begginer in Android programming, I have to do a CountdownTimer that starts from a number selected by the user using a two number pickers (one for Hours and other for minutes).
The characteristics must be:
-The CountdownTimer must work in background and notify the user when it arrives to 00:00. I Have this 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 to make that the CountdownTimer begins from the number selected by the user with the number pickers and the notification when it is done.
Please someone Help Me. :(