title: How to insert my code into startForeground method Android
body: <p>i want run my code into background, for example this loop, no matter:</p>
  
  <pre><code>for (int i = 1; i&lt;=500; i++) {
                      System.out.println(i);
                      try {
                          TimeUnit.SECONDS.sleep(1);
                      } catch (InterruptedException e) {
                          e.printStackTrace();
                      }
                  }
  </code></pre>
  
  <p>Where Do I must insert this code?</p>
  
  <p>MainActivity:</p>
  
  <pre><code>Intent i=new Intent(this, MyService.class);
  startService(i);
  </code></pre>
  
  <p>MyService contaise this:</p>
  
  <pre><code>Intent notificationIntent = new Intent(this, MainActivity.class);
  
          PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
                  notificationIntent, 0);
  
          Notification notification = new NotificationCompat.Builder(this)
                  .setSmallIcon(0)
                  .setContentTitle("My Awesome App")
                  .setContentText("Doing some work...")
                  .setContentIntent(pendingIntent).build();
  
          startForeground(1337, notification);
  </code></pre>