I have tried a lot but my textview is not changing.
Timer should automatically add 30 min to current time and it will be my future time event on button. Click
static final long ONE_MINUTE_IN_MILLIS=60000;//millisecs
Calendar date = Calendar.getInstance();
long t= date.getTimeInMillis();
Date afterAdding30Mins=new Date(t + (30 * ONE_MINUTE_IN_MILLIS));
private void countDownStart() {
runnable = new Runnable() {
@Override
public void run() {
try {
handler.postDelayed(this, 1000);
if (!current_date.after(afterAdding30Mins)) {
long diff = t+ 1800000;
long minutes = (diff / 1000) / 60;
long seconds = (diff / 1000) % 60;
String timeLeftFormattedm = String.format(Locale.getDefault(), "%02d", minutes);
String timeLeftFormatteds = String.format(Locale.getDefault(), "%02d", seconds);
//
tv_minute.setText(timeLeftFormattedm);
tv_second.setText(timeLeftFormatteds);
} else {
linear_layout_1.setVisibility(View.VISIBLE);
linear_layout_2.setVisibility(View.GONE);
handler.removeCallbacks(runnable);
}
} catch (Exception e) {
e.printStackTrace();
}
}
};
handler.postDelayed(runnable, 0);
}
protected void onStop() {
super.onStop();
handler.removeCallbacks(runnable);
}
}