2017-08-06 25 views
0

私のアプリケーションでは、バックグラウンドスレッドから警告メソッドを呼び出す必要があります。 Contextをバックグラウンドスレッドから取得する必要があります。コンテキストを取得している間、私はトークンのNULLエラーを取得しています。ここで私はApplication.Contextを使用していますし、またthis働いていない私のコードXamarin Androidのバックグラウンドスレッドからコンテキストを取得する

Handler h = new Handler(); 
     BackgroService.Event +=() => 
     { 
      Action myAction =() => 
      { 
       Dialog dialog = new Dialog(Application.Context); 
       Android.App.AlertDialog.Builder alert = new Android.App.AlertDialog.Builder(Application.Context, Resource.Style.AlertDialog); 
       alert.SetTitle(""); 
       alert.SetMessage("MSG"); 
       alert.SetPositiveButton(GetString(Resource.String.ok), (senderAlert, args) => 
       { 
        //MyAction 
        dialog.Dismiss(); 
       }); 
       dialog = alert.Create(); 
       dialog.Window.SetType(Android.Views.WindowManagerTypes.ApplicationPanel); 
       dialog.Show(); 


      }; 
      h.PostDelayed(myAction, 1000); 
     }; 

です。誰もがこれを正しく行う考えがありますか?

答えて

0

は、私は、バックグラウンドスレッドの呼び出しからトースト

dialog.Window.SetType(Android.Views.WindowManagerTypes.Toast); 
0

としてWindowManagerTypesを使用してバックグラウンドスレッドからアラートを表示するための解決策を見つける

RunOnUiThread(() => 
{ 
    //show the alert here (you can use the keyword 'this') 
}); 
関連する問題