package com.martin.updroid;

import java.util.Random;

import android.app.IntentService;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.TaskStackBuilder;

public class NewsCheck extends IntentService {

	public NewsCheck() {
		super(NewsCheck.class.getSimpleName());
	}

	@Override
	protected void onHandleIntent(Intent intent) {
		NewsSources nSources = new NewsSources(this);
		NewsCollection nColl = nSources.getAllUnread();

		if (!(nColl.getTitles().length == 0)) {
			NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
					this);
			mBuilder.setAutoCancel(true);
			mBuilder.setContentTitle(nColl.getTitles().length + " new articles");
			String news = "";
			for (int i = 0; i < nColl.getTitles().length; i++) {
				news += nColl.getTitles()[i] + "\n";
			}
			mBuilder.setContentText(news);
			mBuilder.setSmallIcon(R.drawable.ic_action_view_as_list);
			mBuilder.setDefaults(Notification.DEFAULT_ALL);

			Intent resultIntent = new Intent(NewsCheck.this, MainActivity.class);

			TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
			stackBuilder.addParentStack(MainActivity.class);
			stackBuilder.addNextIntent(resultIntent);
			PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(
					0, PendingIntent.FLAG_UPDATE_CURRENT);

			mBuilder.setContentIntent(resultPendingIntent);
			NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

			mNotificationManager.notify(new Random().nextInt(999999999),
					mBuilder.build());
		}

	}

}

@@ -792,57 +792,335 @@
 %0A%09%09%09
-mBuilder.setContentTitle(nColl.getTitles().length
+%0A%09%09%09// Check for null%0A%09%09%09String%5B%5D filtered = new String%5BnColl.getTitles().length%5D;%0A%09%09%09int counter = 0;%0A%09%09%09for (int i = 0; i %3C nColl.getTitles().length; i++) %7B%0A%09%09%09%09if (!nColl.getTitles()%5Bi%5D.contentEquals(%22null%22)) %7B%0A%09%09%09%09%09filtered%5Bcounter%5D = nColl.getTitles()%5Bi%5D;%0A%09%09%09%09%09counter++;%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%09%0A%09%09%09mBuilder.setContentTitle(counter
  + %22
@@ -1184,32 +1184,15 @@
 i %3C 
-nColl.getTitles().length
+counter
 ; i+
@@ -1208,33 +1208,24 @@
 news += 
-nColl.getTitles()
+filtered
 %5Bi%5D + %22%5C
@@ -1378,16 +1378,122 @@
 LT_ALL);
+%0A%09%09%09// Make it big%0A%09%09%09mBuilder.setStyle(new NotificationCompat.BigTextStyle()%0A            .bigText(news));
 %0A%0A%09%09%09Int

Check for null and react accordingly