title: Foreground Service freezes the ui
body: <p>I wanted to create a simple dummy foreground task to get to know its behaviour. Unfortunately i have some problems with it. First the code:</p>
  
  <pre><code>public class ImageSendEmailService extends Service {
  
      @Override
      public void onCreate() {
          super.onCreate();
      }
  
      @Override
      public int onStartCommand(Intent intent, int flags, int startId) {
          if (intent.getAction().equals(ForegroundServiceTags.STARTFOREGROUND_ACTION.getValue())) {
              for (int i = 0; i &lt;= 10; i++) {
                  try {
                      Thread.sleep(1000);
                  } catch (InterruptedException e) {
                      e.printStackTrace();
                  }
  
                  String notificationText = String.valueOf((int) (100 * i / 10)) + " %";
  
                  Notification.Builder builder = new Notification.Builder(this);
                  builder.setContentTitle("Progress");
                  builder.setContentText(notificationText);
                  builder.setTicker("Notification!");
                  builder.setWhen(System.currentTimeMillis());
                  builder.setDefaults(Notification.DEFAULT_SOUND);
                  builder.setAutoCancel(true);
                  builder.setSmallIcon(R.drawable.ic_launcher);
  
                  Notification notification = builder.build();
  
                  this.startForeground(101, this.notification);
              }
          }
  
          return START_STICKY;
      }
  
      @Override
      public IBinder onBind(Intent intent) {
          return null;
      }
  }   
  </code></pre>
  
  <p>The first problem i have is that the service is freezing the UI of the app. The UI is continuing after the <code>Service</code> is done with its work but is frozen while it is doing it.</p>
  
  <p>The second problem i have is that when the work is done the 100% notification is shown in the notifications tab of the device and i cant delete it. I need it to be undeletable while it is doing its work but to be deletable after it finished its work.</p>