关于安卓中AsyncTask使用后的清除缓存问题,安卓中asynctask
程序中使用AsyncTask来实现textview控件的自动更新,程序第一次运行时没有问题。当我按返回键退出,然后再次进入程序时textview的内容就不更新了。必须在最近应用列表中删除这个应用才好用,或者在所有程序列表中的“已缓存”这一项中将程序中止。在按返回键的时候调用过cancel(true)来结束task,依旧没用,下面是task部分代码。想请问如何在代码中完成这类操作?
task = new AsyncTask<Void, Integer, Void>() {
protected Void doInBackground(Void... voids) {
while (true)
{
if (isCancelled()) return null;
time++;
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
publishProgress(time);
}
}
protected void onCancelled() {
super.onCancelled();
}
protected void onCancelled(Void aVoid) {
super.onCancelled(aVoid);
}
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
}
protected void onProgressUpdate(Integer... values) {
textViewStop.setText(""+values[0]);
super.onProgressUpdate(values);
}
}.execute();
用户评论