Blog
    C#
    ADO.Net
    .NET
    ASP.Net & Web Forms
    Custom Controls
    Web Development
    Exception Handling
    XML
    Database
    Security in .Net
    Testing
    Web Services
    Windows Services
    Windows Controls
    WCF
    AJAX
    WPF
    XAML
    Reporting
    Setup
    VB.Net
    LINQ
    JQuery
    SilverLight
    JavaScript
    HTML5
    Crystal Report
    Cloud Computing
    Share Point
    Visual C++
    MVC
    Android
    PHP
    Java
    HTML
    WordPress
    Joomla
    Products
    Drupal
    Windows Phone
    JSON
    LightSwitch
    iPhone/iPad
    Ruby on Rails
    IIS 7
    Windows 8
    CSS/CSS3
    Excel
    MS Access
    Shortcut Keys
    Visual SourceSafe
    Team Foundation Server
    APIs
Follow Us
Follow _MindStick_ on Twitter View MindStick Software's LinkedIn profile View MindStick Software's Facebook profile
Top Contributor
Advertisement
Advertise with Us
Mindstick
Article Article  Forum Forum  Blog Blog  Quiz Quiz  Beginner Beginner  Careers Careers  Contact Contact  Login Login  
Home | Product | Services | About Us | Interview | DeveloperSection | Submit an Article | Submit Blog
Report Abuse Form
Reason:    
 

Home >> Android >> Background Processing in Android
Background Processing in Android

In this blog I am going to explain special Android constructs for concurrency in an Android application.
Views: 3019     Comments: 0
by Rohit Kesharwani on 10/15/2011

Background Processing in Android

Android modifies the user interface via one Thread, the UI Thread. If the programmer does not use any concurrency constructs all the code of an android application run in this UI thread. If we perform a long running operation, it may block our user interface of android application.

Therefore all slow running operations in an Android application should run in the background, e.g. via some way of concurrency constructs of Java language or the Android framework. Slow running operations are network, file and database access and complex calculations.

In this blog I am going to explain special Android constructs for concurrency in an Android application.

Threads

Android supports standard Java Threads. You can use standard Threads and the tools from the package java.util.concurrent to put actions into the background. The only limitation is that you cannot directly update the UI from the background process.

If you need to update the UI from a background task you need to use some Android specific classes. You can use the class android.os.Handler for this or the class AsyncTasks.

Handler

The class Handler can update the UI. A handle provides methods for receiving messages and for runnables. To use a handler you have to subclass it and overide handleMessage() to process messages. To process runables you can use the method post (); you only need one instance of a handler in your activity.

Your thread can post messages via the method sendMessage (Message msg) or sendEmptyMessage.

AsyncTask

The class AsyncTask encapsulates the creation of Threads and Handlers. You must implement the method doInBackground(), which defines what action should be done in the background. This method is being automatically run in a separate Thread. To update the UI you can override the method onPostExecute(). This method will be called by the framework once your action is done and runs within the UI thread.

Title :  
Comment :
Text ColorBackground Color
BoldItalicUnderline
LeftCenterRightJustify
Ordered ListBulleted List
IndentOutdent
Horizontal Rule
SubscriptSuperscript
HyperlinkImage
Design ModeDesign
View HtmlHtml
       
 
Report Abuse Form
Reason:    
 
Latest ArticleRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Latest Blogs by Rohit KesharwaniRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Top Viewed ArticlesRSS Feed
    
    
    
    
    
    
    
    
    
    
Top Viewed BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
Latest Interview QuestionsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Total Online Users: 4924
  
Copyright © 2013MindStick. All Rights Reserved.