Android notification when app is running
<p>I have notification service running in the background. It pops up when there is a new task. When app is closed and notification pop up and if I click on that it goes to MyHomePage.class. But when App is running and I am in different activity and it pops up. It's throwing an error saying NullPointerException. What am I doing wrong. Why can I jump from current activity to MyHomePage.class ?</p>

<pre><code>private void createNewTaskNotification(String s, String id) {
         CharSequence title = "TASK";
         CharSequence message = s;

    notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(R.drawable.checkyes, s,
            System.currentTimeMillis());

    notification.flags = Notification.FLAG_AUTO_CANCEL;

    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.defaults |= Notification.DEFAULT_VIBRATE;

    Intent notificationIntent = new Intent(context, MyHomePage.class);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP );
    PendingIntent pendingIntent = PendingIntent.getActivity(context,
            Integer.parseInt(id), notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    notification.setLatestEventInfo(context, title, message, pendingIntent);
    notificationManager.notify(Integer.parseInt(id), notification);
}
</code></pre>

<p>LogCat:</p>

<pre><code>11-07 12:05:38.870: ERROR/AndroidRuntime(788): FATAL EXCEPTION: main
11-07 12:05:38.870: ERROR/AndroidRuntime(788): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.aa.me.vianet/com.aa.me.vianet.activity.MyHomePage}: java.lang.NullPointerException
11-07 12:05:38.870: ERROR/AndroidRuntime(788):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1751)
11-07 12:05:38.870: ERROR/AndroidRuntime(788):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1767)
11-07 12:05:38.870: ERROR/AndroidRuntime(788):     at android.app.ActivityThread.access$1500(ActivityThread.java:122)
11-07 12:05:38.870: ERROR/AndroidRuntime(788):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1005)
11-07 12:05:38.870: ERROR/AndroidRuntime(788):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-07 12:05:38.870: ERROR/AndroidRuntime(788):     at android.os.Looper.loop(Looper.java:132)
11-07 12:05:38.870: ERROR/AndroidRuntime(788):     at android.app.ActivityThread.main(ActivityThread.java:4028)
11-07 12:05:38.870: ERROR/AndroidRuntime(788):     at java.lang.reflect.Method.invokeNative(Native Method)
11-07 12:05:38.870: ERROR/AndroidRuntime(788):     at java.lang.reflect.Method.invoke(Method.java:491)
11-07 12:05:38.870: ERROR/AndroidRuntime(788):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
11-07 12:05:38.870: ERROR/AndroidRuntime(788):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
11-07 12:05:38.870: ERROR/AndroidRuntime(788):     at dalvik.system.NativeStart.main(Native Method)
11-07 12:05:38.870: ERROR/AndroidRuntime(788): Caused by: java.lang.NullPointerException
11-07 12:05:38.870: ERROR/AndroidRuntime(788):     at com.aa.me.vianet.activity.MyHomePage.onCreate(MyHomePage.java:46)
11-07 12:05:38.870: ERROR/AndroidRuntime(788):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
11-07 12:05:38.870: ERROR/AndroidRuntime(788):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1715)
</code></pre>
