lug*_*eno 7 android back-button android-asynctask android-activity
我有一个AsyncTask,我希望它按下后退按钮时执行.我还希望应用程序返回到之前显示的Activity.似乎我已经设法停止任务,但应用程序没有返回到上一个活动.有任何想法吗?这是我的代码摘录
private class MyTask extends AsyncTask<Void, Void, Void> implements OnDismissListener{
private boolean exception= false;
@Override
protected void onPreExecute(){
pd = ProgressDialog.show(
IscrizioniActivity.this,
"Please wait...",
"Loading the data",
true,
true,
new DialogInterface.OnCancelListener(){
public void onCancel(DialogInterface dialog) {
MyTask.this.cancel(true);
}
}
);
}
@Override
protected Void doInBackground(Void... voids) {
//do something
return (null);
}
@Override
protected void onPostExecute(Void voids) {
pd.dismiss();
//do something
}
public void onDismiss(DialogInterface dialog) {
this.cancel(true);
}
}
Run Code Online (Sandbox Code Playgroud)
问候.
pd.setCancelable(true);
pd.setOnCancelListener(cancelListener);
bCancelled=false;
pd is your progressdialog box
Run Code Online (Sandbox Code Playgroud)
现在使用cancelListner
OnCancelListener cancelListener=new OnCancelListener(){
@Override
public void onCancel(DialogInterface arg0){
bCancelled=true;
finish();
}
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10518 次 |
| 最近记录: |