Created
January 5, 2016 18:30
-
-
Save akexorcist/d0c730d297691f840da7 to your computer and use it in GitHub Desktop.
The answer of someone's question in android developer facebook group https://goo.gl/nA1Vnz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 01-06 01:24:42.095 11422-11422/com.akexorcist.myapplication E/Check: onResponse | |
| 01-06 01:24:42.095 11422-11422/com.akexorcist.myapplication E/Check: Message : มีปัญหาอะไร? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class MainActivity extends AppCompatActivity { | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_main); | |
| ServiceConnection.getService().getData().enqueue(new Callback<ResponseData>() { | |
| @Override | |
| public void onResponse(Response<ResponseData> response, Retrofit retrofit) { | |
| Log.e("Check", "onResponse"); | |
| Log.e("Check", "Message : " + response.body().getMessage()); | |
| } | |
| @Override | |
| public void onFailure(Throwable t) { | |
| Log.e("Check", "onFailure"); | |
| } | |
| }); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public interface MyServiceInterface { | |
| @POST("your_target_url") | |
| Call<ResponseData> getData(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class MyServiceManager { | |
| private static Retrofit retrofit; | |
| private static Retrofit getServiceInstance() { | |
| if(retrofit == null) { | |
| retrofit = new Retrofit.Builder() | |
| .baseUrl("your_base_url") | |
| .addConverterFactory(GsonConverterFactory.create()) | |
| .build(); | |
| } | |
| return retrofit; | |
| } | |
| public static MyServiceInterface getService() { | |
| return getServiceInstance().create(MyServiceInterface.class); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class ResponseData { | |
| String status; | |
| String message; | |
| public String getStatus() { | |
| return status; | |
| } | |
| public String getMessage() { | |
| return message; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| status : 200 | |
| Connection : keep-alive | |
| Content-Length : 63 | |
| Content-Type : application/json; charset=utf-8 | |
| Date : Tue, 05 Jan 2016 18:13:28 GMT | |
| ETag : W/"3f-4db558be" | |
| X-Powered-By : Express | |
| {"status":"ok","message":"มีปัญหาอะไร?"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment