Tuesday, May 26, 2015

ANDROID : IntentService Example

IntentService is a base class for Service  that handle asynchronous requests on demand. Clients send requests through startService(Intent) calls; the service is started as needed, handles each Intent in turn using a worker thread, and stops itself when it runs out of work.
This "work queue processor" pattern is commonly used to offload tasks from an application's main thread. The IntentService class exists to simplify this pattern and take care of the mechanics. To use it, extend IntentService and implement onHandleIntent(Intent). IntentService will receive the Intents, launch a worker thread, and stop the service as appropriate.
All requests are handled on a single worker thread -- they may take as long as necessary (and will not block the application's main loop), but only one request will be processed at a time.



Here I am implemeted a IntentService , wich download the html data of http://www.facebook.com and http://www.google.com

Monday, May 25, 2015

ANDROID : Toogle button with Customised OnCkeckedChangeListner

The CompoundButton.OnCheckedChangeListener is using for creating  callback to be invoked when the checked state of a compound button changed. It can be assign to any view class inheriting the CompoundButton class.

       But i found a problem when using this interface with  view Adapters. The problem is if we set a callback for getting the checked change state to a ToggleButton ,  we can't understand the callback is fired when the user touches the screen or by changing the checked state by code .

Consider the code Below:

ToggleButton toogle = (ToggleButton) findViewById(R.id.btnId);
toogle.setOnCheckedChangeListener(new OnCheckedChangeListener() {
   
   @Override
   public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    
    //
   }
  });


So when the user changed the state of toggleButton by taping in it , the onCheckedChanged will fired.

ToggleButton toogle = (ToggleButton) findViewById(R.id.btnId);
It is also possible to do the same by this


toogle.setChecked(true);

So we cant understand the callback is fired by the user or by the ToogleButton class.


I have solved this issue by creating a custom callBack option for The ToggleButton.  And i am blessed if anyone found this post is helpful :) .