File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Android and the fly likes Android Recipes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Android
Bookmark "Android Recipes" Watch "Android Recipes" New topic

Android Recipes

Stuie Clarky
Ranch Hand

Joined: Nov 09, 2012
Posts: 96

Hi guys,

Just a couple of quick questions about Android. Coming from a production Java background, what do you feel the learning curve / time scale to get up and running with the core of Android? Also, how well does Android deal with concurrency? I have the early stages of an idea floating around in my head, so wondering how well concurrency is handled?


D. Smith

Joined: Jan 11, 2013
Posts: 25

Hi Stuie -

The biggest thing that I tell most Java developers they will need to deal with when coming into Android is figuring out which parts of the SE/EE framework they are used to using are in Android and which parts aren't. The core Java APIs that you are most likely already familiar with in Android represent the implementation from the Apache Harmony project, so not everything will be available. I would suggest perusing the class documentation on in the java.* packages to get a feel for what parts of the API are common. There are also a few APIs that have been replaced but are similar; for instance the package has a VERY similar API to the 2D Canvas drawing available in Oracle Java, but is more Android specific in nature.

The second thing I tell all desktop/server Java developers is to remember that this is a mobile device. While the hardware capabilities of these devices are quite impressive, they are still nowhere near what you might be used to developing for. Memory and CPU time are at a premium, so being judicious with the amount of work you want to do at any given time, and reusing existing objects versus creating new ones whenever possible are two great things to keep in mind as you begin to develop for mobile.

Now, as to your question on concurrency. The Android APIs do include the java.util.concurrent package, so all the classes pure Java has available for thread synchronization (ie. queues, locks, and tasks) can be used in Android applications. In fact, AsyncTask, one of the most widely used Android APIs for doing work on a background thread, is built on top of Executor and FutureTask from this package. You also have access to the full Thread API in your applications. Be wary, though, of what I mentioned earlier...this is still a mobile device. You be very judicious with the amount of parallelization you introduce...10 concurrent threads end up being of no use on a single core machine sitting at 100% usage. Most often, it isn't recommended that you create more than 2N threads in your application (where N is the number of device cores); I usually stick to 2-3 background threads max as a rule of thumb.

I would recommend starting your search with AsyncTask, which allows you to load up tasks serially or using thread pools on the device. In the thread pool case, the ThreadPoolExecutor is provided by the framework, so you can be fairly confident that it won't allow more threads than the system can rightfully handle.

Welcome to the world of Android development!

Android Recipes: A Problem Solution Approach:
Stuie Clarky
Ranch Hand

Joined: Nov 09, 2012
Posts: 96

Brilliant, thanks for that answer

I agree. Here's the link:
subject: Android Recipes
It's not a secret anymore!