Android Notifications via compatibility support library

Special imports:
//You may find v4 support library here

Initialise notification manager:
NotificationManager mNotificationManager=(NotificationManager)

Prepare target intent: This intent will be started when user clicks on the notification which is being sent.
Intent intentTargetActivity=new Intent();
Add the parameters according to the requirement. Mean to say you may pass the context & class object just like starting normal activity. Ensure if you are passing class object, it is your application property :P

Embed target intent into pending intent:
Create a pending intent using target intent. Now, why this PendingIntent??? Answer is if you wish to have a control on how your target intent being launched[like security constraints] then you can do so using pending intents. If you have not specified any then default target specifications will be used to launch the target intent.
PendingIntent  pendingIntentTarget=PendingIntent.getActivity(context,

Prepare the notification:
Note: Pre HoneComb[3.0], Building Notification directly is not directly supported. So you need use compatibility class given in v4 support library. i.e
NotificationCompat.Builder notificationBuilder=new NotificationCompat.Builder(this);
Finally build the notification instance and set specific flags if you wish any ..
      notificationInfo.flags|=Notification.FLAG_AUTO_CANCEL;//Notification gets cancelled once user clicks on it.
Value addition:
You may wish to customize notification behavior? A few are shown below
//Don’t forget to add in manifest:
// <uses-permission android:name="android.permission.VIBRATE"/>
//where VIBRATE_PATTERN is something {100,200,100,200};

//similarly you may set audio effect to your notification
//by setting uri of sound file like:
//Main thing: custom view!!
//Else you may wish to use the default notification behavior by:

Finally notify! :
How to send..? Like this:
//Using notification count itself as ID..
//Note using this notification ID we can controle post notification behaviour
// i.e we may cancel the notification if it exists or check for
//presence of the notification with same id.. etc..
mNotificationManager.notify(NOTIFICATION_ID, notificationInfo);

Need a working soldier? Go to My SampleNotification project on GitHub

Happy coding


Swing - How to Run-On-UI-Thread


Is your UI changes are not reflecting when your Java-Swing application is running? OR Do you want to run UI stuffs from non-UI thread? Below snippet will be handy for you..

new Runnable()
            public void run()
                  //UI processing done here..
                  //Finally validate..

Happy coding