2017-12-24 12 views
0
public class AppApi extends AsyncTask<String, Void, String> { 

    private OkHttpClient client; 
    private Request request; 
    private MediaType JSON; 
    private String URL; 
    private RequestBody body; 

    public AppApi(JSONObject obj) { 
     client = new OkHttpClient(); 
     JSON = MediaType.parse("application/json; charset=utf-8"); 
     URL = "http://serverapi.domain.com/user/login"; 
     Log.d("Information",obj.toString()); 
     body = RequestBody.create(JSON, obj.toString()); 
     request = new Request.Builder() 
       .url(URL) 
       .post(body) 
       .build(); 
    } 

    @Override 
    protected String doInBackground(String... strings) { 
     // execute fonksiyonu cagrilarak calistirilir 
     try { 
      Response response = client.newCall(request).execute(); 
      return response.body().string(); 
     } catch (Exception ex) { 
      Log.e("doInBackground()", ex.getMessage()); 
      return null; 
     } 
    } 

    protected void onProgressUpdate(Integer... progress) { 
     // setProgressPercent(progress[0]); 
    } 

    protected void onPostExecute(Long result) { 
     // showDialog("Downloaded " + result + " bytes"); 
    } 
} 

    btnLogin.setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(View view) { 
     login(); 
    } 
} 

LoginActivity.Java.Android - 애플리케이션에서 서버에 로그인 할 때 프레임 건너 뛰기. (비동기)

그래서 응용 프로그램의 문제점은 https 서버에 제대로 로그인 할 수 없다는 것입니다. Android Studio에서는 프레임을 건너 뛰고 있다고 말합니다.

I/작성자 : 건너 뛴 77 프레임! 응용 프로그램이 주 스레드에서 많은 작업을 수행 중일 수도 있습니다 ( ).

우리가 의도적으로 잘못된 암호를 입력하려고

, 그것은 더 많은 프레임을 건너 뜁니다. (200ish) 나는 우리가 비동기 작업 측에서 올바르게 코딩의 대부분을했다고 생각. 반환 값을 어떻게 확인할 수 있습니까? 문제를 어떻게 해결할 수 있습니까?

답변

0

는 백그라운드 스레드로 빌드 요청을 넣어뿐만 아니라

private JSONObject obj; 
public AppApi(JSONObject obj) { 
     this.obj = obj; 
    } 

    @Override 
    protected String doInBackground(String... strings) { 
     // execute fonksiyonu cagrilarak calistirilir 
     try { 
client = new OkHttpClient(); 
     JSON = MediaType.parse("application/json; charset=utf-8"); 
     URL = "http://serverapi.domain.com/user/login"; 
     Log.d("Information",obj.toString()); 
     body = RequestBody.create(JSON, obj.toString()); 
     request = new Request.Builder() 
       .url(URL) 
       .post(body) 
       .build(); 
      Response response = client.newCall(request).execute(); 
      return response.body().string(); 
     } catch (Exception ex) { 
      Log.e("doInBackground()", ex.getMessage()); 
      return null; 
     } 
    } 
+0

.i.e 지금은 건너 뛰는 문제가 계속 서버하지만 프레임의 응답을 얻을 수보십시오. – ebm1440

+0

로그에 대한 모든 통화를 제거하려고 시도했습니다. –

+0

효과가있었습니다. 고마워요! – ebm1440