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

Customizing Android ListView Items with Custom ArrayAdapter Tutorial in Category Android at EzzyLearning.com 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 Marvelous work... keep it up.. Posted by ajay on 31 Aug 2011 Your solution assumes 5 entries cloudy, showers, stormy etc... Posted by Mark Manickaraj on 20 Sep 2011 You can fill weather data variable from the data coming from any of your method or service method.Weather weather_data[] = youservice.GetWeatherData(); Posted by Waqas Anwar on 21 Sep 2011 When you add enough items to scroll the scroll is laggy. Posted by Mark Manickaraj on 22 Sep 2011 Hey thanks. Posted by ruchi on 20 Nov 2011 hie , there seem a problem with ur code ..works slow and list view takes time to load while scrolling ..can u help ?? Posted by gaurav on 21 Nov 2011 great!!! Thanks!!!!

java: how can i set a class's field by a field name that stored in a variable Rich-Style Formatting of an Android TextView - ChrisUmbel.com 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 In the end this isn't limited to formatting. Example Essentially this code will set a TextView's text to the familiar, "Lorem ipsum dolor sit amet" and perform the following formatting: Make "Lorem" red Make "ipsum" a 1.5 times bigger than what the TextView's setting Make "dolor" display a toast message when touched Strike through "sit" Make "amet" twice as big as the TextView's setting, green and a link to this site The results of which will look something like: Note that we set the TextView's movement method to a LinkMovementMethod instance. Next Steps This covers the fundamental concepts, but there are many extensions of CharacterStyle I haven't covered here. Sat Aug 28 2010 18:25:02 GMT+0000 (UTC)

Android – Simple XML DOM Parser Example for Reading Response From InputStream | Vikas Patel's Blog 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: Use SOAP call, HTTP Get method, HTTP Post method and many more.. I have one Web service method with Post call structure: POST /api.asmx/validateCredentials HTTP/1.1 Host: api.mywebsite.com Content-Type: application/x-www-form-urlencoded Content-Length: length username=string&password=string Now I want to call it from Android HTTP Post method. I’ll do it like: Now First of all I wanted my response as String. So I use Buffer reader to read the data from response object. Now I can see the response in LogCat. <? Here you can see some tags and actually we need those values!! So I can now use this “String” object to parse the XML. To parse the XML we have several methods like SAX parser, DOM parser XML pool parser etc. Like this: Like Loading...

Android Button background image pressed/highlighted and disabled states without using multiple images | Shiki 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: The code is also available on GitHub. App Widget Design Guidelines New Guides for App Designers! Check out the new documents for designers at Android Design. App widgets (sometimes just "widgets") are a feature introduced in Android 1.5 and vastly improved in Android 3.0 and 3.1. A widget can display an application's most timely or otherwise relevant information at a glance, on a user's Home screen. The standard Android system image includes several widgets, including a widget for the Analog Clock, Music, and other applications. Figure 1. This document describes how to design a widget so that it fits graphically with other widgets and with the other elements of the Android Home screen such as launcher icons and shortcuts. For information about developing widgets, see the App Widgets section of the Developer's Guide. Standard Widget Anatomy Typical Android app widgets have three main components: A bounding box, a frame, and the widget's graphical controls and other elements. Figure 2. Determining a size for your widget Figure 3. Figure 4. Figure 5.

widget The widget package contains (mostly visual) UI elements to use on your Application screen. You can also design your own. To create your own widget, extend View or a subclass. Java implementation file - This is the file that implements the behavior of the widget. ApiDemos sample application has an example of creating a custom layout XML tag, LabelView. LabelView.java - The implementation file res/values/attrs.xml - Definition file res/layout/custom_view_1.xml - Layout file Interfaces Classes Enums Exceptions Simple Android application from scratch in IntelliJ IDEA 11.0 - IntelliJ-Wiki From IntelliJ-Wiki IntelliJ IDEA supports development of applications to be executed on mobile phones that run under the Android operating system. Besides general coding assistance, the IDE lets you test Android applications on user-configured emulators of physical devices. IntelliJ IDEA helps: This tutorial will walk you step-by-step through developing and launching a simple Android application. You are working with IntelliJ IDEA Ultimate edition version 11.0 or higher. Let’s start from the very beginning and create a project for our application. Choose File | New Project on the main menu or click the Create New Project icon on the Welcome screen (Image 1). Image 1. On the first page of the New Project wizard (Image 2), make sure that the option Create project from scratch is selected. Image 2. On the second page of the wizard (Image 3), choose the parent folder (1) to create the project in and specify the name of the project (2). Image 3. Image 4. Configuring Android SDK and Java SDK Image 5.

Related: