title: Is there a rule of thumb in Instantiating in Android?
body: <p>I'm a beginner in Android programming and I came across with this code below.</p>
  
  <pre><code>public void email(View view){
      Intent intent = new Intent(this, NotificationActivity.class);
      PendingIntent pendingIntent = PendingIntent.getActivity(this, 
                                    0, intent, 0);
  
      NotificationCompat.Builder builder = new NotificationCompat.Builder(
              getApplicationContext())
              .setTicker("NEW EMAIL!!!")
              .setSmallIcon(android.R.drawable.ic_dialog_email)
              .setAutoCancel(true)
              .setContentText("This is a new E-mail!!!")
              .setContentIntent(pendingIntent);
  
      NotificationManager manager =(NotificationManager)getSystemService(
              Context.NOTIFICATION_SERVICE);
      manager.notify(0, builder.build());
  </code></pre>
  
  <p>It made me angry to see that creating an instance of <code>PendingIntent</code> is: </p>
  
  <pre><code>PendingIntent.getActivity(etc.)
  </code></pre>
  
  <p>and creating an instance of <code>NotificationManager</code> is: </p>
  
  <pre><code> (NotificationManager)getSystemService(etc.)
  </code></pre>
  
  <p>While creating an instance of  <code>NotificationCompat.Builder</code> is: </p>
  
  <pre><code>new NotificationCompat.Builder(getApplicationContext())
  </code></pre>
  
  <p>How can you know when to use the word "new" or the method <code>getSystemService()</code> and so on. Is there a universal rule of instantiating or should I learn it one by one, for every class?</p>
  
  <p>Thanks for your help!</p>