I have the following code which runs a task every second, but I also want the task to stop after 10 seconds. Can this logic be implemented with a handler in which I'm using? I've tried implementing a counter with a while loop but couldn't get it to work
mHandler = new Handler();
mUpdateUI = new Runnable() {
public void run() {
mVistaInspectionDate = HousingFragment.getVistaInspectionDate();
mVistaInspectionDateTextView.setText(mVistaInspectionDate);
if (mVistaInspectionDate != null) {
mHandler.removeCallbacks(mUpdateUI);
}
mHandler.postDelayed(mUpdateUI, 1000); // 1 second
}
};
mHandler.post(mUpdateUI);