没事

    xiaoxiao2021-03-26  26

    package zhangyapeng.bwie.com.eggplantdoctor; import android.app.Application; import zhangyapeng.bwie.com.eggplantdoctor.base.network.Singleton; /** * Created by zhang on 2017/1/9. */ public class Qz extends Application { public static Singleton singleton; @Override public void onCreate() { super.onCreate(); singleton = Singleton.getInStance(); } } / import android.app.Application; import zhangyapeng.bwie.com.recycleview.okhttp.Singon; /** * Created by zhang on 2017/2/5. */ public class Qz extends Application { public static Singon singleton; @Override public void onCreate() { super.onCreate(); singleton = Singon.getInStance(); } } // package zhangyapeng.bwie.com.recycleview.okhttp; import android.os.Message; import android.telecom.Call; import com.google.gson.Gson; import com.squareup.okhttp.Callback; import com.squareup.okhttp.OkHttpClient; import com.squareup.okhttp.Request; import com.squareup.okhttp.Response; import java.io.IOException; /** * Created by zhang on 2017/2/5. */ public class Singon { private static volatile Singon singleton; private final Gson gson; private Singon() { gson = new Gson(); } public static Singon getInStance() { if (singleton == null) { synchronized (Singon.class) { if (singleton == null) { singleton = new Singon(); } } } return singleton; } public void netWork(String url, final MyHandler handler){ //创建okHttpClient对象 OkHttpClient mOkHttpClient = new OkHttpClient(); //创建一个Request final Request request = new Request.Builder() .url(url) .build(); //new call com.squareup.okhttp.Call call = mOkHttpClient.newCall(request); //请求加入调度 call.enqueue(new Callback() { @Override public void onFailure(Request request, IOException e) { Message obtain = Message.obtain(); obtain.what=0; handler.sendMessage(obtain); } @Override public void onResponse(final Response response) throws IOException { String json = response.body().string(); Message obtain1 = Message.obtain(); obtain1.what = 2; obtain1.obj = json; handler.sendMessage(obtain1); } }); } }
    转载请注明原文地址: https://ju.6miu.com/read-661788.html

    最新回复(0)