title: Creating a notification from a asynctask
body: <p>I run this task when my mainactivity gets paused and stop the task when mainactivity resumes.
  But cant get notifications work at the asynctask.
  i get a nullpointerexception at the build() method of the notification builder.</p>
  
  <pre><code>public class Alarm extends AsyncTask&lt;String, Void, String&gt;{
      private Context mContext;
      private int NOTIFICATION_ID = 1;
      private Notification noti;
      private NotificationManager nm;
      PendingIntent contentIntent;
      protected void onPreExecute(String... params) {
          Intent notificationIntent = new Intent(mContext.getApplicationContext(), MainActivity.class);
          contentIntent = PendingIntent.getActivity(mContext.getApplicationContext(),
                  0, notificationIntent,
                  PendingIntent.FLAG_CANCEL_CURRENT);
      }
  
  
      private void createNotification() {
          noti = new NotificationCompat.Builder(mContext)
          .setContentIntent(contentIntent)
          .setContentTitle("New mail from ")
          .setContentText("deneme")
          .setSmallIcon(R.drawable.ic_launcher)
          .build();
              nm = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
              nm.notify(NOTIFICATION_ID, noti);
          }
  
  
      protected String doInBackground(String... params) {     
      if(MainActivity.alarmToggle.isChecked()){
          while(true){
          try{    
              Thread.sleep(1000);
              StringBuilder builder = new StringBuilder();
              HttpClient client = new DefaultHttpClient();
              HttpGet requestedUrl = new HttpGet("http://www.btcturk.com/api/ticker");
              HttpResponse response;
              response = client.execute(requestedUrl);        
              HttpEntity entity = response.getEntity();
              if (entity != null) {
                  InputStream inputStream = entity.getContent();
                  BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
                  for (String line = null; (line = bufferedReader.readLine()) != null;) {
                      builder.append(line).append("\n");
                  }
              }
              Map&lt;String, Double&gt; map = new Gson().fromJson(builder.toString(), new TypeToken&lt;HashMap&lt;String, Double&gt;&gt;() {}.getType());
              if(map.get("last") &lt;= MainActivity.dusukLimitVal &amp;&amp; MainActivity.dusukLimitVal != 0){           
                  createNotification();
              }   
  
              if(map.get("last") &gt;= MainActivity.yuksekLimitVal &amp;&amp; MainActivity.yuksekLimitVal != 0){         
                  createNotification();
              }       
          }catch(Exception e){
              e.printStackTrace();
          }
              if (isCancelled()) break;
          }
      }
          return null;
      }
  }
  </code></pre>