您好我有这样的问题,我有一个asynctask和进度对话框,当我旋转我的手机失败时,我知道该活动失败了,我们需要创建新的。
所以代码。
public class GetWeather extends AsyncTask<String, Void, WeatherInfo> {
FragmentActivity activity;
public GetWeather(FragmentActivity a){
activity = a;
}
static ProgressDialog progressDialog;
public void showDialog() {
progressDialog = new ProgressDialog(activity);
/*Some stuff for dialog*/
progressDialog.show();
}
@Override
protected void onPreExecute() {
showDialog();
}
protected void onPostExecute(WeatherInfo result){
progressDialog.dismiss();
}
}
和我的活动课
public class MyActivity extends FragmentActivity implements CityList.OnItemSelectedListener {
GetWeather weather = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
weather = (GetWeather) getLastCustomNonConfigurationInstance();
if (weather != null){
weather.activity = this;
weather.showDialog();
}
它失败了。如何修复?谢谢。