我有一个简单的应用程序,首先显示MainActivity,然后在MainActivity可见后,我显示TransparentActivity,之后在点击事件中关闭TransparentActivity并创建并显示对话框。在最后一步时,我遇到了错误。
错误
Failure delivering result ResultInfo{who=null, request=1234, result=-1, data=Intent { }} to activity {com.example.kylu.layout/com.example.kylu.layout.GuidePhotoAlbum}: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
MainActivity
public class MainActivity extends FragmentActivity
{
public static boolean flag=false;
private static int REQUEST_CODE = 1234;
@Override public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.mylayout);
}
@Override
protected void onResume() {
super.onResume();
//transparentShows only once
if(!flag)
{
Intent i = new Intent(this, TransparentTip.class);
startActivityForResult(i, REQUEST_CODE);
flag=true;
}
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (REQUEST_CODE == requestCode) {
if (resultCode == Activity.RESULT_OK) {
Toast.makeText(this, "Show dialog", Toast.LENGTH_SHORT).show();
DialogChoiceActivity dialogChoiceActivity = new DialogChoiceActivity();
dialogChoiceActivity.show(getSupportFragmentManager(),"mydialog");
} else if (resultCode == Activity.RESULT_CANCELED) {
Toast.makeText(this, "Don't show dialog", Toast.LENGTH_SHORT).show();
}
}
}
透明提示
public class TransparentTip extends Activity {
public static int countTransp=0;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.transparent_tip);
Button ok=(Button)findViewById(R.id.bToK);
}
public void buttonClick(View view)
{
if (view.getId() == R.id.bToK)
{
final Intent intent = new Intent();
setResult(Activity.RESULT_OK, intent);
finish();
}
}
DialogChoiceActivity
public class DialogChoiceActivity extends DialogFragment {
LayoutInflater inflater;
View v;
public Dialog onCreateDialog(Bundle savedInstanceState) {
inflater = getActivity().getLayoutInflater();
v = inflater.inflate(R.layout.dialog_email, null);
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("Email " + " 1/10");
builder..setNegativeButton("Exit", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(getActivity(), MainActivity.class);
startActivity(intent);
}
});
return builder.create();
}
}
透明界面不再可见后,我想在MainActivity上显示对话框。我尝试在onResume中显示此对话框,但是遇到了类似的错误。