2017-11-03 16 views
0

저는 Volley Requests를 만드는 컨트롤러가 있습니다. 인터넷 연결을 사용할 수 없다면 코드 진행을 차단하고 싶습니다. 따라서 인터넷 연결이 가능한지 사용할 수 없으며 연결을 확인하는 단추가 있으면 연결이 있으면 대화 상자가 닫힙니다. 내가 연결을 확인하기 위해 필요하지만 나는 루프 동안 대화가 오는 언급하지만, 때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(); 

당신은을 사용한다

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

참고 : 여기에

내 코드입니다 AysncTaskLoader 대신 AsyncTask를 사용하면이 스레드는 동시에 실행되지 않습니다. 또한 각 루프 사이에서 잠시 기다리는 것이 가장 좋습니다. 정확히 CheckInternetConnection에서 무슨 일이 일어나고 있는지 잘 모르겠습니다. 건배!