Restful API service

前端 未结 11 1513
清歌不尽
清歌不尽 2020-11-22 14:28

I\'m looking to make a service which I can use to make calls to a web-based REST API.

Basically I want to start a service on app init then I want to be able to ask t

相关标签:
11条回答
  • 2020-11-22 15:00

    Also when I hit the post(Config.getURL("login"), values) the app seems to pause for a while (seems weird - thought the idea behind a service was that it runs on a different thread!)

    No you have to create a thread yourself, a Local service runs in the UI thread by default.

    0 讨论(0)
  • 2020-11-22 15:01

    I would highly recommend the REST client Retrofit.

    I have found this well written blog post extremely helpful, it also contains simple example code. The author uses Retrofit to make the network calls and Otto to implement a data bus pattern:

    http://www.mdswanson.com/blog/2014/04/07/durable-android-rest-clients.html

    0 讨论(0)
  • 2020-11-22 15:07

    I know @Martyn does not want full code, but I think this annotation its good for this question:

    10 Open Source Android Apps which every Android developer must look into

    Foursquared for Android is open-source, and have an interesting code pattern interacting with the foursquare REST API.

    0 讨论(0)
  • 2020-11-22 15:08

    Robby provides a great answer, though I can see you still looking for more information. I implemented REST api calls the easy BUT wrong way. It wasn't until watching this Google I/O video that I understood where I went wrong. It's not as simple as putting together an AsyncTask with a HttpUrlConnection get/put call.

    0 讨论(0)
  • 2020-11-22 15:10

    Note that the solution from Robby Pond is somehow lacking: in this way you only allow todo one api call at a time since the IntentService only handles one intent at a time. Often you want to perform parallel api calls. If you want todo this you have to extend Service instead of IntentService and create your own thread.

    0 讨论(0)
  • 2020-11-22 15:11

    Developing Android REST client applications has been an awesome resource for me. The speaker does not show any code, he just goes over design considerations and techniques in putting together a rock solid Rest Api in android. If your a podcast kinda person or not, I'd recommend giving this one at least one listen but, personally I've listened to it like 4 or five times thus far and I'm probably going to listen to it again.

    Developing Android REST client applications
    Author: Virgil Dobjanschi
    Description:

    This session will present architectural considerations for developing RESTful applications on the Android platform. It focuses on design patterns, platform integration and performance issues specific to the Android platform.

    And there are so many considerations I really hadn't made in the first version of my api that I've had to refactor

    0 讨论(0)
提交回复
热议问题