2017-11-03 17 views
0

私はVolley Requestsを作成しているコントローラを持っていますが、インターネット接続が利用できない場合はコードを処理しないようにしたいので、インターネット接続使用できません。また、接続を確認するためのボタンがあります。接続があれば、ダイアログは閉じられます。whileループがあるとダイアログのフラグメントが表示されない

ここに私のコードです:

if(!CheckInternetConnection.getInstance(context).isOnline()){ 
    NoInternetConnection noInternetConnection=new NoInternetConnection(); 
    noInternetConnection.setContext(context); 
    noInternetConnection.show(fragmentManager,"NoInternetConnection"); 
    while (!CheckInternetConnection.getInstance(context).isOnline()); 
} 

注私はwhileループ、ダイアログが起動しますが、私はそれが接続

答えて

0
new AsyncTask<Object, Object, Object>() { 
     @Override 
     protected Object doInBackground(Object[] objects) { 
      while (!CheckInternetConnection.getInstance(context).isOnline()) { 
      } 
      return null; 
     } 

     @Override 
     protected void onPostExecute(Object o) { 
      /* 
      Call some method in the DialogFragment to dismiss it. 
      */ 
      noInternetConnection.dismissDialog(); 
     } 
    }.execute(); 

をチェックする必要があるしかしあなたが使用する必要があることをコメントし、ということAysncTaskLoaderをAsyncTaskの代わりに使用すると、このスレッドは同時に実行されません。また、各ループの間にいくつかの時間を待つことをお勧めします。私はあなたのCheckInternetConnectionで何が起こっているのかが分かりません。乾杯!

関連する問題