示例#1
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            //as we expect this to happen only rarely (having a foreground service running when unlocked),
            //we don't try to handle this better
            //But at least explain to the user what happened!
            ((NotificationManager)GetSystemService(Context.NotificationService)).CancelAll();
            AlertDialog.Builder b = new AlertDialog.Builder(this);
            b.SetMessage(Resource.String.killed_by_os);
            b.SetPositiveButton(Android.Resource.String.Ok, delegate
            {
                Intent i = new Intent(this, typeof(FileSelectActivity));
                i.AddFlags(ActivityFlags.ClearTask | ActivityFlags.NewTask);
                StartActivity(i);

            });
            b.SetNegativeButton(Resource.String.cancel, delegate { });
            b.SetTitle(GetString(AppNames.AppNameResource));
            b.SetOnDismissListener(this);
            var dialog = b.Create();
            dialog.Show();
        }
示例#2
0
        private static AlertDialogInfo CreateDialog(
            string content,
            string title,
            string okText = null,
            string cancelText = null,
            Action<bool> afterHideCallbackWithResponse = null)
        {
            var tcs = new TaskCompletionSource<bool>();

            var builder = new AlertDialog.Builder(ActivityBase.CurrentActivity);
            builder.SetMessage(content);
            builder.SetTitle(title);

            AlertDialog dialog = null;

            builder.SetPositiveButton(okText ?? "OK", (d, index) =>
            {
                tcs.TrySetResult(true);

                // ReSharper disable AccessToModifiedClosure
                if (dialog != null)
                {
                    dialog.Dismiss();
                    dialog.Dispose();
                }

                if (afterHideCallbackWithResponse != null)
                {
                    afterHideCallbackWithResponse(true);
                }
                // ReSharper restore AccessToModifiedClosure
            });

            if (cancelText != null)
            {
                builder.SetNegativeButton(cancelText, (d, index) =>
                {
                    tcs.TrySetResult(false);

                    // ReSharper disable AccessToModifiedClosure
                    if (dialog != null)
                    {
                        dialog.Dismiss();
                        dialog.Dispose();
                    }

                    if (afterHideCallbackWithResponse != null)
                    {
                        afterHideCallbackWithResponse(false);
                    }
                    // ReSharper restore AccessToModifiedClosure
                });
            }

            builder.SetOnDismissListener(new OnDismissListener(() =>
            {
                tcs.TrySetResult(false);

                if (afterHideCallbackWithResponse != null)
                {
                    afterHideCallbackWithResponse(false);
                }
            }));

            dialog = builder.Create();

            return new AlertDialogInfo
            {
                Dialog = dialog,
                Tcs = tcs
            };
        }