background preloader

Multithreading For Performance

Multithreading For Performance
[This post is by Gilles Debunne, an engineer in the Android group who loves to get multitasked. — Tim Bray] A good practice in creating responsive applications is to make sure your main UI thread does the minimum amount of work. Any potentially long task that may hang your application should be handled in a different thread. Typical examples of such tasks are network operations, which involve unpredictable delays. Users will tolerate some pauses, especially if you provide feedback that something is in progress, but a frozen application gives them no clue. In this article, we will create a simple image downloader that illustrates this pattern. An Image downloader Downloading an image from the web is fairly simple, using the HTTP-related classes provided by the framework. static Bitmap downloadBitmap(String url) { final AndroidHttpClient client = AndroidHttpClient.newInstance("Android"); final HttpGet getRequest = new HttpGet(url); A client and an HTTP request are created. Demo Future work

Related:  performance

Customizing Android ListView Items with Custom ArrayAdapter Tutorial in Category Android at how to add onItemClick event based on Custom array adapter above Posted by kadek iwan on 27 Aug 2011 You can use listView1.setOnItemClickListener event. See my following tutorial for an example. Posted by Waqas Anwar on 27 Aug 2011 Use your Android phone as a wireless keyboard and mouse to remote control your computer So, I decided to get a Lenovo ThinkPad x120e for development purposes. The Chromebook I got from Google I/O made me appreciate the value of a light laptop with massive battery life, and the experience of installing Ubuntu on it made me think that I could actually start using something like that for development purposes. Of course, the disadvantages of the Chromebook are that it’s not necessarily easy to install different OSes on it, and the stupid, stupid touchpad. The SSD can be upgraded, so that’s not a big deal. –RANT– One of the reasons I got into Android way back in the G1 days was that I wanted a decent smartphone, but having played around with iPhones, I really liked physical keyboards as well, so along comes the G1, and I was instantly sold. The trend towards buttonless trackpads is terrible for the same reasons soft keyboards aren’t the end all, be all.

Android Webservice example In this post, we will be discussing how to invoke web service from Android application. When web methods are invoked from inside Android application, the application gets back the data from the server in the form of XML. The response which has been received can be parsed and rendered in the application as needed. If you are looking for tutorial on consuming the web service which you created using Java or Dot Net, please follow below links: How to call Java web service in android

StrictMode StrictMode is a developer tool which detects things you might be doing by accident and brings them to your attention so you can fix them. StrictMode is most commonly used to catch accidental disk or network access on the application's main thread, where UI operations are received and animations take place. Keeping disk and network operations off the main thread makes for much smoother, more responsive applications. By keeping your application's main thread responsive, you also prevent ANR dialogs from being shown to users. Note that even though an Android device's disk is often on flash memory, many devices run a filesystem on top of that memory with very limited concurrency.

Rich-Style Formatting of an Android TextView - Even a developer-friendly mobile platform like Android can have a developer feeling a little lost when trying to perform simple tasks when you're unfamiliar with the platform. One of these simple, however poorly documented, tasks is rich-style text formatting within a TextView. SpannableString Getting Started in Android Game Development If you're interested in developing a game for the Android platform, there is a lot you need to know. I'm the developer of Light Racer, Light Racer 3D, Antigen, Deadly Chambers and Wixel, which are currently available on the Android Market. I've also been involved with the development of about 5 other games for Android and iOS and am co-author of Beginning Android Games 2nd Edition. I've developed games before but the original Light Racer was my first Android application and I learned quite a bit about writing Android games that I'd like to share with everyone. I even wrote an online book detailing the development of Light Racer 3D, which is full of how-tos and useful code snippets.

Scheduling Background Tasks in Android Periodically your Android application might need to perform a task, such as checking a server for updates. The AlarmManager class can be used to schedule and execute operations that need to occur even if the application isn’t running. The AlarmManager class enables the scheduling of repeated alarms that will run at set points in the future. Android 3.0 Hardware Acceleration [This post is by Romain Guy, who likes things on your screen to move fast. —Tim Bray] One of the biggest changes we made to Android for Honeycomb is the addition of a new rendering pipeline so that applications can benefit from hardware accelerated 2D graphics. Android – Simple XML DOM Parser Example for Reading Response From InputStream Hi, I am trying to use simple XML DOM Parser for my HTTP response. Basically I am calling .Net webservice and I need to parse response. Let me also cover calling the .Net webservice. Webservice can be called/consumed by may way. For Example:

Code Style Guidelines for Contributors The rules below are not guidelines or recommendations, but strict rules. Contributions to Android generally will not be accepted if they do not adhere to these rules. Not all existing code follows these rules, but all new code is expected to. Java Language Rules We follow standard Java coding conventions.

Android Tab Layout with Swipeable Views My previous article explains about Android Tab Layout and it got very good ranking in search engines. But unfortunately TabHost is deprecated by android in favor of fragments. So it is suggested that use fragment to achieve tab layout. This article shows you how to create tab layout using fragments and viewpager. Also you can swipe between tab view as it is the functionality of viewpager which is not possible when using TabHost. Smoothing performance on Fragment transitions Suppose you're doing a pretty standard Fragment replacement with a custom animation: getSupportFragmentManager() .beginTransaction() .setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out) .replace(, new MyFragment()) .commit(); You may notice that the performance can be a bit rough, not as smooth as you'd like.

Android Button background image pressed/highlighted and disabled states without using multiple images In Android, if you provide custom background images for buttons, you will lose the pressed and disabled image effects. The common way to fix that is to provide additional images for those states. I’m lazy and I find this inconvenient especially during the prototyping phase of app development. To use this, just replace your original button declarations like this: To this: Here’s a sample output using this custom button:

TimingLogger Class Overview A utility class to help log timings splits throughout a method call. Typical usage is: TimingLogger timings = new TimingLogger(TAG, "methodA"); // ... do some work A ... timings.addSplit("work A"); // ... do some work B ... timings.addSplit("work B"); // ... do some work C ... timings.addSplit("work C"); timings.dumpToLog(); The dumpToLog call would add the following to the log: