Saturday, February 11, 2012

Broadcast receivers

Broadcast:
Broadcasting is a mechanism in which android will broadcast a message to all the apps. And apps should register for the particular broadcast message to receive it. This mechanism is used to notify all the system wide messages. Example of some predefined broadcast messages.

ACTION_BATTERY_CHANGED
ACTION_POWER_CONNECTED
ACTION_POWER_DISCONNECTED
ACTION_SHUTDOWN

see "Standard Broadcast Receiver Action" in Android Intent for more information.

Code snippet
----------- Broadcast receiver ------------------
class TestBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// Action to be done on receiving the broadcast.
}
}
---------- Android Manifest xml -----------------
To use this TestBroadcastReceiver an entry should be made in Android Manifest xml file

--------Broadcast Sender ----------------
Intent intent = new Intent ("com.test.TEST_MESSAGE");
intent.sendBroadcast(intent);


Wednesday, February 8, 2012


Guys,

This is our first blender 3D image.
I ll upload improved version of this android monster later.
Singleton Design Pattern:

- provides global access to object
- Ensure that only one instance of a class

Implementation:

class s'd contain,

- private constructor.
- private static instance of the class.
- one more public static method which retruns class instance.


Code snippet:

class Sing // Singleton class
{
private static Sing instance; //private static instance
private Sing() {
//Private constructor
}
public static Sing getInstance(){
//
if(instance == null)
instance = new Sing();
return instance;
}
public void display()
{
System.out.println("Singleton onject");
}
}

class Singleton {

public static void main(String[] args) {

Sing.getInstance().display();
}

}


Here, other class cant create instance of this class because of private constructor.
So they can invoke getInstance mehod of the class using class name and it will return class instance.


Usages:

- Logger class : provides global access
- configuration classes
- Accessing shared Resources

Tuesday, February 7, 2012

http://www.youtube.com/watch?v=cdvaPyq_eBU

Hey guys!!

This is really a good video. I prefer to see full video in one go. Make your self some time and see these.

-Happy androiding ;)