If you want to using asynctask to run countdown timer and if you want to show on UI, you can not use doInBackground, because it can not meddle to UI.
I think you should use thread for this issue. if you want/dont want timer continue to run when the app is minimize, you can use a boolean variable to control (must use runOnUiThread to meddle to UI)
How to use:
boolean stop=false;
runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
if (!stop) {
//YOUR CODE HERE
}
}
});
If you want to stop timer when app minimize, use can set stop=true
in onPause()
of activity
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
stop=true;
}
and if you want timer re-play when activity resume, you can set stop=false
in onResume()
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
stop=false;
}