Pages

August 31, 2010

Blogger Code Formattings | Sample

"Show Me The Code" ( a title of davanum's blog ) !! 
To present snippets in most readable form in blog post, code-snippets needs to be formmated with Syntax Highlighter. Below is the code formatting sample...
// Comment
public class Interesting{
  public Interesting() {
}
 
public void Fun() {
  /* Another Comment
  on multiple lines */
  int x = 9;
}
}

Find out how to format code like this sample on Syntax Highlighter for Blog | a Blog Post 
hope this helps you to "Show Your Snippets" - Sharing is Learning !!

Samsung Galaxy Tablet

Android : hey iPad , Here i come , Samsung Galaxy Tablet official Launch this week. 
Tablet Competition Begins.. 

Samsung Galaxy S has great success all over the world, same expecting from TABLET.



Runs on Android 2.2..


For Indian user it would be delighting :)  Download Millions of Apps from Android Market.
I guess now Google will soon create new Category on Droid Market: Android Tablet Apps
Find out More on Samsung Galaxy Tablet | Official Site ....

August 29, 2010

Android Tips : onClickListener:onClick()


In this post , we will learn "Easy/Effective way to write code in onClickListener's onClick() to know which Button is clicked"

Inside onClick(View view) : write a switch-case as shown in below code.

Android UI Thread & Massive Work Thread

Many times Android Application becomes in-responsive due to heavy load on UI thread & user gets "FORCE CLOSE" message.

Avoid performing long-running operations (such as network I/O) directly in the UI thread — the main thread of an application where the UI is run — or your application may be blocked and become unresponsive. Here is a brief summary of the recommended approach for handling expensive operations:

There is simple solution to make application that does Massive work & need to frequently update UI.
Solution is to create a mechanism using  android.os.handler ,
  1. Create a Handler object in your UI thread
  2. Spawn off worker threads to perform any required expensive operations
  3. Post results from a worker thread back to the UI thread via Message Object.
  4. Update the views on the UI thread as needed
Below is simple solution:

public class MyActivity extends Activity {

    [ . . . ]
    // Need handler for callbacks to the UI thread
    final Handler mHandler = new Handler();

    // Create runnable for posting
    final Runnable mUpdateResults = new Runnable() {
        public void run() {
            updateResultsInUi();
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        [ . . . ]
    }

    protected void startLongRunningOperation() {

        // Fire off a thread to do some work that we shouldn't do 

        // directly in the UI thread 

        Thread t = new Thread() {
            public void run() {
                mResults = doSomethingExpensive();
                mHandler.post(mUpdateResults);
            }
        };
        t.start();
    }

    private void updateResultsInUi() {

        // Back in the UI thread -- update our UI elements based on 

        //the data in mResults
        [ . . . ]
    }
}
Article on Android.com | Common Task