title: Show AlertDialog from ViewModel using MvvmCross
body: <p>I am using MvvmCross for creation my Android-app and I faced with the following problem:</p>
  
  <p>When I'm trying to show AlertDialog, that was created in ViewModel, the</p>
  
  <p>"<strong>Unhandled Exception: Android.Views.WindowManagerBadTokenException</strong>" appears.</p>
  
  <pre><code>public class MyViewModel : MvxViewModel
  {
      public ICommand ShowAlertCommand { get; private set; }
  
      public AuthorizationViewModel()
      {
          ShowAlertCommand = new MvxCommand(() =&gt;
              {
                  var adb = new AlertDialog.Builder(Application.Context); 
                  adb.SetTitle("Title here");
                  adb.SetMessage("Message here");  
                  adb.SetIcon(Resource.Drawable.Icon);
                  adb.SetPositiveButton("OK", (sender, args) =&gt; { /* some logic */});   
                  adb.SetNegativeButton("Cancel", (sender, args) =&gt; { /* close alertDialog */});
  
                  adb.Create().Show();
              });
      }
  }
  </code></pre>
  
  <p>When I was <a href="https://stackoverflow.com/questions/2634991/android-1-6-android-view-windowmanagerbadtokenexception-unable-to-add-window">researching</a> I have found that it happens because of transmission of the  reference to the Context but not on the Activity in the AlertDialog.Builder.</p>
  
  <p>In <a href="https://stackoverflow.com/questions/11845520/unable-run-progressdialog-badtokenexception-while-showind">this topic</a> I found the following decision:
  Receive references to the current  Activity through the use of GetService(), but I didn't found mvvmcross plugins  for work with IMvxServiceConsumer, IMvxAndroidCurrentTopActivity interfaces.</p>
  
  <p><strong>My question</strong> is can I show  AlertDialog from ViewModel? And how can I get the reference to  Activity, but not to the Application.Context?
  And what is the correct way to close AlertDialog that the user would stay on the current View?</p>