这是进步对话片段的示例程序。通常它工作正常,但方向改变了它崩溃..
出现此错误
java.lang.IllegalSt ateException: Can not perform this action after onSaveInstanceSt ate
at android.support.v4.app.FragmentManagerImpl.checkSt ateLoss(FragmentManager.java:1375)
at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1393)
at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:636)
at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:615)
at android.support.v4.app.DialogFragment.show(DialogFragment.java:138)
at com.inntot.langtest.MainActivity$LongOper ation.onPostExecute(MainActivity.java:75)
at com.inntot.langtest.MainActivity$LongOper ation.onPostExecute(MainActivity.java:57)
at android.os.AsyncTask.finish(AsyncTask.java:632)
at android.os.AsyncTask.access$600(AsyncTask.java:177)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
at android.os.Handler.disp atchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5253)
at java.lang.reflect.Method.invoke(N ative Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:117)
public class MainActivity extends ActionBarActivity
{
Button change;
ProgressDialogFragment p;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
change = (Button)findViewById(R.id.buttonchange);
change.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
p = ProgressDialogFragment.newInstance("Hai","Hello");
p.show(getSupportFragmentManager(),"update");
new LongOperation().execute("");
}
});
}
private class LongOperation extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
for (int i = 0; i < 5; i++) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.interrupted();
}
}
return "Executed";
}
@Override
protected void onPostExecute(String result) {
p.dismissDialog();
p = ProgressDialogFragment.newInstance("Hai","Home");
p.show(getSupportFragmentManager(),"update");
}
@Override
protected void onPreExecute() {}
@Override
protected void onProgressUpdate(Void... values) {}
}
}
public class ProgressDialogFragment extends DialogFragment
{
String Title,Message;
static ProgressDialogFragment newInstance(String Title,String Message){
ProgressDialogFragment PDF= new ProgressDialogFragment();
Bundle bundle = new Bundle();
bundle.putString("Title",Title);
bundle.putString("Message",Message);
PDF.setArguments(bundle);
return PDF;
}
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setCancelable(false);
setRetainInstance(true);
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
ProgressDialog dialog = new ProgressDialog(getActivity(), getTheme());
dialog.setTitle(getArguments().getString("Title"));
dialog.setMessage(getArguments().getString("Message"));
dialog.setIndeterminate(true);
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
return dialog;
}
public void dismissDialog()
{
dismiss();
}
@Override
public void onDestroyView() {
if (getDialog() != null && getRetainInstance())
getDialog().setOnDismissListener(null);
super.onDestroyView();
}
}
任何人都可以帮我解决问题......