I'm doing an app and I want give to the user the option to close the app automatically at the selected hour using the Timepicker. I knwo that i have to use the alarm manager, but i dont knw hot to combine with timepicker and close the app with it
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_contadorpro);
timePicker = (TimePicker) findViewById(R.id.timePicker);
button = (Button)findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Contador Activado", Toast.LENGTH_LONG).show();
timePicker.clearFocus();
final Calendar _calendar = Calendar.getInstance();
final int hour = timePicker.getCurrentHour();
final int minute = timePicker.getCurrentMinute();
Thread _thread = new Thread() {
@Override
public void run() {
try {
Calendar _calendar = Calendar.getInstance();
int _currentHour = _calendar.get(Calendar.HOUR);
int _currentMinute = _calendar.get(Calendar.MINUTE);
if(_currentHour == hour && _currentMinute == minute){
System.exit(0);
}
} catch (Exception e) {
e.printStackTrace();
}
}
};
_thread.start();
}
});
}
}