Alibaba fit tool Class Analysis in mobile development

Source: Internet
Author: User

Alibaba fit tool Class Analysis in mobile development

Replace MySerVice with your own interface

Package com. example. a05_weekexamdemo.util;

Import okhttp3.OkHttpClient;

Import into fit2.20.fit;

Import Export fit2.adapter. rxjava. RxJavaCallAdapterFactory;

Import into fit2.converter. gson. GsonConverterFactory;

/**

* Created by yujie on April /12/30.

*/

Public class extends fithelper {

Public static OkHttpClient okHttpClient;

Public static MySerVice mySerVice;

Static {

GetOkHttpClient ();

}

Public static OkHttpClient getOkHttpClient (){

If (okHttpClient = null ){

Synchronized (OkHttpClient. class ){

If (okHttpClient = null ){

OkHttpClient = new OkHttpClient ();

}

}

}

Return okHttpClient;

}

Public static MySerVice getMySerVice (String url ){

If (mySerVice = null ){

Synchronized (MySerVice. class ){

If (mySerVice = null ){

MySerVice = createMyService (MySerVice. class, url );

}

}

}

Return mySerVice;

}

Private static T createMyService (Class tClass, String url ){

T t = new fit. Builder ()

. BaseUrl (url)

. AddConverterFactory (GsonConverterFactory. create ())

. AddCallAdapterFactory (RxJavaCallAdapterFactory. create ())

. Build ()

. Create (tClass );

Return t;

}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.