« Posts under Java

Parallel Image loading performance in Android

I just ran into the problem that I have to load a whole bunch of images in an Android application, so I wondered about the performance of parallel image loading and how many images can be loaded simultaneously. Therefore I wrote a small benchmark app that loads about 100 images (each between 4 and 7 KB) from a webpage. I admit, the app could be written better, but for my purpose it should be fine.

I measured the time in seconds that it took to load all images without displaying them in a View. 0 Threads means that all images were loaded in a sequence. A Thread count above 0 means that I created a new AsyncTask for each image and ran n of them at the same time.

»Read More

Login to the Foursquare API v2 from Android with OAuth

Once you figured out how OAuth works, you might ask yourself how this principle works from within a native Android app. It’s actually easier then expected at first. There exist some libraries that can make our life somehow easier, but I decided not to use any of them and to do everything from scratch.

This is the OAuth workflow for Foursquare:

  • A call to the Foursquare server is made with the client id and a redirect URL (has to be in a browser)
  • The user accepts the access request of the application
  • Foursquare calls the redirect URL with special code as parameter
  • The Foursquare server has to be called again with the client id, client secret, the code and the redirect URL (not in the browser anymore)
  • Foursquare returns now the access token which has to be saved by the app
  • Further calls to the Foursquare API can be made with the token

»Read More

Login to Foursquare with an Android App using OAuth

Note: This tutorial is for the Foursquare API V1. A version for v2 can be found here.

Although the Foursquare login process is pretty easy, it took me some time to figure out how this could be done from an Android application. The problem here is, that I don’t want a Popup window for the OAuth login. There’s a different requirement for the whole login process.

A standard OAuth login process consists of this flow:

  • Create consumer with application token and secret
  • Get login URL from service
  • Redirect the user to the login URL
  • User grant or deny access to service
  • Get the access token and secret

But in a mobile application, without a URL redirection, what we actually want is something like this:

  • Create consumer with application token and secret
  • Login to service
  • Get the access token and secret »Read More