background preloader


Related:  lw

JakeWharton/butterknife Android Bootstrap JakeWharton/Android-ViewPagerIndicator Retrofit Introduction Retrofit turns your REST API into a Java interface. public interface GitHubService { @GET("/users/{user}/repos") List<Repo> listRepos(@Path("user") String user);} The RestAdapter class generates an implementation of the GitHubService interface. RestAdapter restAdapter = new RestAdapter.Builder() .setEndpoint(" .build(); GitHubService service = restAdapter.create(GitHubService.class); Each call on the generated GitHubService makes an HTTP request to the remote webserver. List<Repo> repos = service.listRepos("octocat"); Use annotations to describe the HTTP request: URL parameter replacement and query parameter support Object conversion to request body (e.g., JSON, protocol buffers) Multipart request body and file upload API Declaration Annotations on the interface methods and its parameters indicate how a request will be handled. Request Method Every method must have an HTTP annotation that provides the request method and relative URL. @GET("/users/list") Download

kevinsawicki/http-request Services A Service is an application component that can perform long-running operations in the background and does not provide a user interface. Another application component can start a service and it will continue to run in the background even if the user switches to another application. Additionally, a component can bind to a service to interact with it and even perform interprocess communication (IPC). For example, a service might handle network transactions, play music, perform file I/O, or interact with a content provider, all from the background. A service can essentially take two forms: Started Bound Regardless of whether your application is started, bound, or both, any application component can use the service (even from a separate application), in the same way that any component can use an activity—by starting it with an Intent. The Basics Should you use a service or a thread? To create a service, you must create a subclass of Service (or one of its existing subclasses). Service

gson - A Java library to convert JSON to Java objects and vice-versa Gson is a Java library that can be used to convert Java Objects into their JSON representation. It can also be used to convert a JSON string to an equivalent Java object. Gson can work with arbitrary Java objects including pre-existing objects that you do not have source-code of. There are a few open-source projects that can convert Java objects to JSON. Gson Goals Provide simple toJson() and fromJson() methods to convert Java objects to JSON and vice-versa Allow pre-existing unmodifiable objects to be converted to and from JSON Extensive support of Java Generics Allow custom representations for objects Support arbitrarily complex objects (with deep inheritance hierarchies and extensive use of generic types) Gson Downloads Gson 2.3.1 downloads at Maven Central Gson Documentation Gson API: Javadocs for the current Gson release Gson user guide: This guide contains examples on how to use Gson in your code. Please use the google-gson Google Group to discuss Gson, or to post questions.

Android : Volley and Gson tutorial Android Volley is the new way to make network requests. It has a lot of advantages : configurable thread pool, request priority, caching, request cancel. AsyncTask is no more needed and this is a good new as AsyncTask is known for its memory leak issues. In this quick step tutorial, i show the piece of source code to make it work with google gson library. Test before If you wish to test before, you can install the application with the following link. Your app ideaMichenuxFree Prerequisite At this time, there is no release of volley library so you have to download the source code and copy it inside your project. git clone In the activity Declare a new attribute of type RequestQueue : private RequestQueue requestQueue; In the onCreate method, initialize the RequestCode and let’s call our startRequest method : this.requestQueue = Volley.newRequestQueue(this.getActivity()); startRequest() This is my startRequest method.

greenDAO – Android ORM for SQLite | greenDAO is a light & fast ORM solution that maps objects to SQLite databases. OkHttp Overview HTTP is the way modern applications network. It’s how we exchange data & media. OkHttp is an HTTP client that’s efficient by default: HTTP/2 support allows all requests to the same host to share a socket. OkHttp perseveres when the network is troublesome: it will silently recover from common connection problems. Using OkHttp is easy. OkHttp supports Android 2.3 and above. Examples Get a URL This program downloads a URL and print its contents as a string. OkHttpClient client = new OkHttpClient(); String run(String url) throws IOException { Request request = new Request.Builder() .url(url) .build(); Response response = client.newCall(request).execute(); return response.body().string();} Post to a Server This program posts data to a service. Download ↓ v3.4.1 JAR You'll also need Okio, which OkHttp uses for fast I/O and resizable buffers. The source code to OkHttp, its samples, and this website is available on GitHub. Maven Gradle compile 'com.squareup.okhttp3:okhttp:3.4.1' Contributing

roboguice/roboguice Gson User Guide - gson Serializing and Deserializing Collection with Objects of Arbitrary Types Sometimes you are dealing with JSON array that contains mixed types. For example: The equivalent Collection containing this is: Collection collection = new ArrayList(); collection.add("hello"); collection.add(5); collection.add(new Event("GREETINGS", "guest")); Where the Event class is defined as: class Event { private String name; private String source; private Event(String name, String source) { = name; this.source = source; You can serialize the collection with Gson without doing anything specific: toJson(collection) would write out the desired output. However, deserialization with fromJson(json, Collection.class) will not work since Gson has no way of knowing how to map the input to the types. Option 1: Use Gson's parser API (low-level streaming parser or the DOM parser JsonParser) to parse the array elements and then use Gson.fromJson() on each of the array elements.This is the preferred approach. Compact Vs.