background preloader


Facebook Twitter

Stephanenicolas/robospice. Greenrobot/EventBus. Android Async HTTP Clients: Volley vs Retrofit - Instructure Tech Blog. We recently released a new version of our mobile app for Android. Although it was a huge improvement from previous installments in terms of features, design, and usability, there was one nagging issue in the back of our minds: speed. There are times when the app isn’t as snappy as we’d like it to be. After some profiling, benchmarks, and common sense, we determined that retrieving data from the API (the networking) was the bottleneck. The Old Way: AsyncTasks As of the latest version, we use the built-in AsyncTasks to retrieve data from Canvas’ servers.

Introducing Volley and Retrofit Luckily, there are a few third party libraries that provide support for concurrent background threads, network caching, as well as other features that clean up networking code substantially. How We Decided The decision to switch the architecture of our networking code was not an easy one to make. From outwards appearances, they are quite similar in usage. RetroFit Wins Resources: Retrofit: Volley: RoboSpice-InfoGraphics.png (600×5417) Note1. Demonstrate HTTP caching with OkHttp and Retrofit. Android: Loaders versus AsyncTask. One of the biggest pieces of Android that I have neglected to learn about would be Loaders. Seeing as it’s time for me to learn it, perhaps I can help you out a bit with it as well. My main interest with the Loader concept is how it melds with the tried and true AsyncTask, and if it’s really better or not. AsyncTask Before getting into the Loader concept, it’s important to have a good idea of what the AsyncTask is and what it’s used for within Android.

If you have written any sort of application for Android, chances are you have played with the AsyncTask, or at the very least heard of it. Configuration changes can mess things upPausing an activity doesn’t pause the AsyncTaskA fair amount of boilerplate code (which means more possible errors) Loaders The AsyncTask isn’t the only way to do background processing in Android, though. Loaders (specifically the CursorLoader) really shine when using Cursors within Android to pull data.

Related Whitepaper: Handling Runtime Changes. To test that your application restarts itself with the application state intact, you should invoke configuration changes (such as changing the screen orientation) while performing various tasks in your application. Your application should be able to restart at any time without loss of user data or state in order to handle events such as configuration changes or when the user receives an incoming phone call and then returns to your application much later after your application process may have been destroyed.

To learn how you can restore your activity state, read about the Activity lifecycle. However, you might encounter a situation in which restarting your application and restoring significant amounts of data can be costly and create a poor user experience. In such a situation, you have two other options: Retain an object during a configuration change Allow your activity to restart when a configuration changes, but carry a stateful object to the new instance of your activity. RoboSpice Motivations - Aplicaciones Android en Google Play. Join the G+ community and register as a tester to get latest alpha/beta versions: Andlytics collects statistics from the Google Play Developer Console. It lets you track active installs, total installs, ratings, and comments for all your Android apps that are published on Google Play. Andlytics can also collect AdMob statistics, including revenue, requests and impressions.

It supports background syncing of stats and notifications for when changes occur. Google does not provide a public API for collecting statistics. Andlytics is open source, please feel free to contribute via GitHub, Andlytics is not associated with Google in any way. "Google Apps for Business" and Multi-connected developer accounts are not supported yet.

Keywords: Developer console, developer tools, android developers. Loaders. RoboSpice presentation. Android Fundamentals: Properly Loading Data. The UI thread is a bad place for lengthy operations like loading data. You never know how long data will take to load, especially if that data is sourced from a content provider or the network. Android 3.0 (Honeycomb) introduced the concept of Loaders and, in particular, the CursorLoader class that offloads the work of loading data on a thread, and keeps the data persistent during short term activity refresh events, such as an orientation change. We'll incorporate the Loader as a new feature in our ongoing tutorial series building a yet-to-be-named tutorial reader application. If you were paying close attention to our last tutorial, Android Fundamentals: Working With Content Providers, you may have noticed that we took a shortcut. We used the managedQuery() method of the Activity class, which is a newly deprecated method.

This method represents the "old" way of letting an activity manage a cursor. You need to make several changes to the onCreate() method of the TutListFragment class. Implementing Loaders (part 3) | Android Design Patterns. This post introduces the Loader<D> class as well as custom Loader implementations. This is the third of a series of posts I will be writing on Loaders and the LoaderManager: First things first, if you haven’t read my previous two posts, I suggest you do so before continuing further. Here is a very brief summary of what this blog has covered so far. Life Before Loaders (part 1) described the flaws of the pre-Honeycomb 3.0 API and its tendency to perform lengthy queries on the main UI thread. These UI-unfriendly APIs resulted in unresponsive applications and were the primary motivation for introducing the Loader and the LoaderManager in Android 3.0.

Understanding the LoaderManager (part 2) introduced the LoaderManager class and its role in delivering asynchronously loaded data to the client. Loader Basics They encapsulate the actual loading of data. Loaders are a somewhat advanced topic and may take some time getting used to. What Makes Up a Loader? A task to perform the asynchronous load. Android Fundamentals: Properly Loading Data. Loading Data in the Background. Android Components. The CommonsWare Android Components, or CWAC, are open source libraries to help solve various tactical problems with Android development. Most CWAC components are packaged as a tiny JAR file that you can add to your project (e.g., drop it in libs/), requiring at most other CWAC JARs as dependencies. Most are also available as AAR artifacts in a CommonsWare repository, ready for inclusion in your Gradle-based project build scripts.

The current supported CWAC components, and their GitHub repositories, are: cwac-adapter: Provides an AdapterWrapper, a simple wrapper class that, by default, delegates all ListAdapter methods to a wrapped ListAdapter. And, in case you were wondering, CWAC is pronounced like "quack". Condesales/easyFoursquare4Android. Path/android-priority-jobqueue. Android and REST. Path/android-priority-jobqueue. Nlefler/NLFoursquare-Android. Android Background Processing with Handlers and AsyncTask and Loaders. Android Background Processing with Handlers and AsyncTask and Loaders - Tutorial Copyright © 2011, 2012, 2013 Lars Vogel Android Threads, Handlers AsyncTask This tutorial describes the usage of Threads, Handlers and AsyncTask in your application. It also covers how to handle the application lifecycle together with threads.

It is based on Eclipse 4.2, Java 1.6 and Android 4.2. 1. Android modifies the user interface and handles input events from one single user interface thread. Android collects all events in a queue and processed an instance of the Looper class. 1.2. If the programmer does not use any concurrency constructs, all code of an Android application runs in the main thread and every statement is executed after each other.

If you perform a long lasting operation, for example accessing data from the Internet, the application blocks until the corresponding operation has finished. Note Android enforces a worst case reaction time of applications. 3. 3.1. 3.2. In your own code: 4. 5.1. Tip. Google I/O 2010 - Android REST client applications. Thunsaker/soup. Creating a REST library using Retrofit & OkHttp. I've been tasked to modernize our application's networking layer. We have been writing our own network manager to deal with http 302 redirect and caching responses, but there are many opensource project that already does these things very well.

I've looked into RoboSpice and Volley as the more popular choices for doing networking in Android. I found that they're a good candidate as an improved AsyncTask as well as providing caching. However both framework are closely related to the Activity context and doesn't work as well when put into a Service such as ones that I intent to make with a SyncAdapter. We needed a lower level framework. Retrofit Supports Https In Retrofit's home page, their example uses https, so clearly it supports it. Converts JSON to POJO Retrofit use GSON by default to convert Http bodies to and from JSON. Edit request header and body Retrofit allow header information to be set statically using annotation or at runtime using a RequestIntercepter. OkHttp. Saving (and Retrieving) Android Instance State - Part 1 - Intertech Blog. Why do we need to save instance state? Android activities have a lifecycle (for a diagram of this lifecycle see here). As an activity becomes partially hidden (paused) or fully hidden (stopped), possibly even destroyed, your applications need a way to keep valuable state (i.e. data) the activity has obtained (probably from user input) or created even after the activity has gone away.

As an example, an orientation change can cause your activity to be destroyed and removed from memory and then recreated again. Unless you avail yourself to certain state saving mechanisms, any data your activity has at the time of orientation change can be completely lost in this seemingly simple act. How do we save activity instance state? The Activity class provides the first, and possibly easiest, means of saving and restoring activity state. The onSaveInstanceState( ) method is a callback method that is not shown on most Activity lifecycle diagrams.

Saving State using onSaveInstanceState( ) Example Wrap Up. Robospice/dependencies/1.4.12 at repository · stephanenicolas/robospice. 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. OkHttp. Overview HTTP is the way modern applications network. It’s how we exchange data & media. Doing HTTP efficiently makes your stuff load faster and saves bandwidth. 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. Maven Gradle compile 'com.squareup.okhttp3:okhttp:3.4.1' Contributing License. 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. The whole source code of the project is also available on github. The airport screen use the volley library.

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 : Gson stuff for Volley. 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. Android Bootstrap. AndroidBootstrap/android-bootstrap. Libraries to use for easy asynchronous REST web requests and image loading | Mohammed Saudi's Blog. 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. Your app idea. Andersgoransson/eatbookexamples. AndroidDev people you should follow | Lemberg Blog. Gson User Guide - gson. Context, What Context? - by Dave Smith of Double Encore.

Handling Runtime Changes. Romannurik/Android-WizardPager. Modern techniques for implementing REST clients on Android 4.0 and below – Part 2 - Rest interaction in Android. Consume Webservice in Android using intentService | Surviving w/ Android. What is Context in Android - SimpleCodeStuffs|SimpleCodeStuffs. The Central Repository Search Engine. Android RoboSpice with GoogleHttpClient. Android Networking Without the Pain de Colin Lee en Prezi. SpiceManager in Application · Issue #211 · stephanenicolas/robospice.