title: how to set a timer and perform an action for it, in android application
body: <p>I'm developing an application in Android Studio. How i can set timer and then perform an action at that time?</p>
  
  <p>Im getting system date and time... and getting date and time by user..
  then i have to compare both and perform an action for it.
  Need Help Here is my code:</p>
  
  <p>=========================================================================</p>
  
  <pre><code>import android.app.DatePickerDialog;
  import android.app.TimePickerDialog;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.Button;
  import android.widget.DatePicker;
  import android.widget.TextClock;
  import android.widget.TextView;
  import android.widget.TimePicker;
  
  import java.sql.Time;
  import java.text.DateFormat;
  import java.text.SimpleDateFormat;
  import java.time.Year;
  import java.util.Calendar;
  
  public class MainActivity extends AppCompatActivity implements
          DatePickerDialog.OnDateSetListener, TimePickerDialog.OnTimeSetListener{
  
      TextView textView, textView2;
      TextClock textClock;
      TimePicker timePicker;
      DatePicker datePicker;
      Button button, button2;
      Calendar calendar;
      SimpleDateFormat simpleDateFormat;
      String Date;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
  //        textClock = (TextClock) findViewById(R.id.textClock);
  //        textClock.setFormat12Hour("hh:mm:ss aa");
  //        String time = textClock.getText().toString();
  
          textView     = (TextView) findViewById(R.id.textView);
          textView2     = (TextView) findViewById(R.id.textView2);
          button     = (Button) findViewById(R.id.button);
                                                                                                       //Showing current time
          calendar = Calendar.getInstance();
          simpleDateFormat= new SimpleDateFormat("dd-MM-yyyy HH:mm");
          Date = simpleDateFormat.format(calendar.getTime());
          textView.setText(Date);
  
  
          button.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
  
                  Calendar c = Calendar.getInstance();
  
                  int year = c.get(Calendar.YEAR);
                  int month = c.get(Calendar.MONTH);
                  int day = c.get(Calendar.DAY_OF_MONTH);
  
                  DatePickerDialog datePickerDialog = new DatePickerDialog(MainActivity.this, MainActivity.this, year, month, day);
                  datePickerDialog.show();
              }
          });
  
  
      }
  
  
      @Override
      public void onDateSet(DatePicker datePicker, int i, int i1, int i2) {
  
          int yearFinal = i;
          int monthFinal = i1+1;
          int dayFinal = i2;
  
          Calendar c = Calendar.getInstance();
          int hour = c.get(Calendar.HOUR_OF_DAY);
          int minute = c.get(Calendar.MINUTE);
  
          TimePickerDialog timePickerDialog = new TimePickerDialog( MainActivity.this,
                  MainActivity.this, hour, minute);
          timePickerDialog.show();
  
  
      }
  
      @Override
      public void onTimeSet(TimePicker timePicker, int i, int i1) {
  
          hourFinal = i;
          minuteFinal = i1;
  
          textView2.setText(earFinal + monthFinal + dayFinal + hourFinal + minuteFinal);
  
  
  
      }
  }
  </code></pre>