I am trying to schedule a timer using the timertask. I want to freeze the UI when the task is running using the ProgressDialog. I am using AsyncTask with TimerTask to achieve the desired results. But when I add Progress Dialog code to TimerTask Runnable, it throws Runtime Exception. Below is the code for TimerTask, Any help would be appreciated. Thanks in advance.
public class MyTimerTask extends TimerTask { Context contxt; public MyTimerTask(Context cn){ contxt=cn;
}
public void run() {
try {
pd=ProgressDialog.show(contxt, "Searching For Records", "Please wait...", true, true);
reqtype="GO";
_getRecords=new InitTask();
_getRecords.execute(contxt);
} catch (Exception e) {
Log.e(">>>>>>>>>>>> Error executing MyAsyncTask: ", e.getMessage(), e);
}
}
}