Xamarin.Android AlertDialog Show()得到RuntimeException

时间:2017-08-16 07:52:27

标签: c# android xamarin.android alertdialog android-alertdialog

我有一个ActivityActivityA),用户可以点击列表中的一个项目,它会打开下一个ActivityActivityB):

public class ActivityA : ReactiveAppCompatActivity<LoginViewModel>
    {
        ListView AvailableProjectListView;
        AvailableProjectAdapter ProjectAdapter;

        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Create your application here
            SetContentView(Resource.Layout.AvailableProjects);

            AvailableProjectListView.Events().ItemClick
                                    .Subscribe(result => StartDownloadActivity(result.Position));
        }

        void StartDownloadActivity(int selectedProject)
        {
            //do some things here before open the next activity

            Intent downloadIntent = new Intent(this, typeof(ActivityB));
            StartActivity(downloadIntent);
        }
}

在下一个ActivityActivityB)中,如果下载过程出错,我会显示AlertDialog

this.WhenAnyValue(x => x.ViewModel.DownloadStatusCode)
    .Where(x => x == APIRequestResult.UnknownError)
    .Subscribe(result =>
    {
        this.ViewModel.UserAction = LoginUserAction.None;
        ShowUnknownErrorAlert();
    });

void ShowUnknownErrorAlert()
{
    this.ViewModel.DownloadStatusCode = APIRequestResult.None;

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.SetTitle(Resource.String.download_error);
    builder.SetMessage(Resource.String.please_try_again_later);
    builder.SetNegativeButton(Resource.String.ok, (senderAlert, args) => {
        var alert = senderAlert as AlertDialog;
        if (alert != null && alert.IsShowing)
        {
             alert.Dismiss();
        }
        Finish();
    });

    AlertDialog dialog = builder.Create();
    dialog.Show();
}

AlertDialog第一次正常运作。但是,在我从ActivityB再次打开ActivityA后,警报对话框未显示,并且显示以下消息:

  

[Dialog] show mWindowManager.addView RuntimeException

可能有什么问题?

0 个答案:

没有答案