Android loopj Async Http crashes after 1.4.5 update

前端 未结 5 2019
谎友^
谎友^ 2021-02-04 05:35

The new update for Android loopj Async Http lib is out and they changed a lot. Now you need to manually set Looper.prepare() otherwise it uses synchronious mode ins

5条回答
  •  一个人的身影
    2021-02-04 05:54

    I solved the issue by passing parameter in AsyncHttpResponseHandler(Looper.getMainLooper()) like this.

    First of all i used two classes one is MainActivity and Download Class. In MainActivity class, i call post method which is implement in the Downloadclass. Then Download class contains POST () which was import from my library like import com.loopj.android.http.*;

    MainActivity.Class

    clientObj.post(context,url,entity, "application/json", new AsyncHttpResponseHandler(Looper.getMainLooper()) {
    
    @Override
    public void onSuccess(int statusCode,org.apache.http.Header[] headers,byte[] responseBody) {
            System.out.println(" Success ="+responseBody);
    }
    @Override
    public void onFailure(int statusCode,org.apache.http.Header[] headers,byte[] responseBody, Throwable error) {
        System.out.println( "Failure");
    }
    });
    

    DownLoad.Class

        AsyncHttpClient asynClient = new AsyncHttpClient();
    
    
    void post(Context context,String url, StringEntity entity,String string, AsyncHttpResponseHandler asyncHttpResponseHandler) {
        asynClient.addHeader("Accept", "application/json");
        asynClient.addHeader("Content-type", "application/json");
        asynClient.post(context, url, entity, "application/json", asyncHttpResponseHandler );
    }
    

提交回复
热议问题