我有一个使用 android-support-v4 片段 API 的“hello world”-ish 示例应用程序。该活动由一个按钮组成,单击它将显示一个DialogFragment。但是,即使使用了 setRetainInstance(true),旋转等配置更改也会导致对话框消失。
知道如何解决这个问题吗?
RetFragment.java
package me.local.HelloFroyo;
import android.os.Bundle;
import android.support.v4.app.*;
import android.util.Log;
import android.view.*;
public class RetFragment extends DialogFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.hello_dialog_fragment, container);
}
@Override
public void onDestroy() {
super.onDestroy();
Log.e("RET", "onDestroy");
}
}
MainActivity.java
package me.local.HelloFroyo;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
public class MainActivity extends FragmentActivity {
private static final String TAG_DLG = "myFragDlg";
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
this.setContentView(R.layout.activity_main);
}
public void onShowClick(View v) {
RetFragment ret = new RetFragment();
ret.show(getSupportFragmentManager(), TAG_DLG);
}
}