title: How do I change a Activity from a Handler?
body: <p>I need a Service for Bluetooth communication. Sometimes things go wrong. I want to show that in an Activity. But How? 
  Broadcasts? <code>sendbroadcast</code> is not known in the <code>handler</code></p>
  
  <p>I had a look at:
  <a href="https://stackoverflow.com/questions/19541290/getting-a-handler-from-a-thread-from-service-to-activity">Getting a Handler from a Thread from Service to Activity</a>
  But I dont get it.</p>
  
  <p>Here are my classes:</p>
  
  <pre><code>public class TestService extends Service {
  
      public ExampleLooper looperThread = new ExampleLooper();
  
      @Override
      public int onStartCommand(Intent intent, int flags, int startId) {
  
          String input = intent.getStringExtra("Nachricht");
  
          Intent notificationIntent = new Intent(this, MainActivity.class);
          PendingIntent pendingIntent = PendingIntent.getActivity(this,
                  0, notificationIntent, 0);
  
          Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID)
                  .setContentTitle("Rufknopf")            // TODO in @string/... packen
                  .setContentText(input)
                  .setSmallIcon(R.drawable.ic_android)
                  .setContentIntent(pendingIntent)
                  .build();
  
          startForeground(1, notification);
  
          ExampleHandler handler = new ExampleHandler();
  
          Message msg = Message.obtain();
          msg.what = intent.getIntExtra("LooperMessage",-1);
  
          looperThread.handler.sendMessage(msg);
  
        //  return super.onStartCommand(intent, flags, startId);
          return START_NOT_STICKY;
      }
  
      @Override
      public void onCreate(){
          super.onCreate();
          Log.d(TAG, "onCreate: Service das erste mal gestartet.");
          looperThread.start();
      }
  
      @Override
      public void onDestroy(){
          Log.d(TAG, "onDestroy: ");
          looperThread.looper.quit();
  
  
          super.onDestroy();
      }
  }
  </code></pre>
  
  <pre><code>
  public class ExampleLooper extends Thread {
  
      private static final String TAG = "ExampleLooperThread";
  
      public Looper looper;
      public Handler handler;
  
      @Override
      public void run() {
          Looper.prepare();
  
          looper = Looper.myLooper();
  
          handler = new ExampleHandler();
  
          Looper.loop();
  
  
          Log.d(TAG, "End of run()");
      }
  }
  </code></pre>
  
  <pre><code>public class ExampleHandler extends Handler {
  
      public static final int FALL1 = 10;
      public static final int FALL2 = 20;
  
      @Override
      public void handleMessage(Message msg) {
          super.handleMessage(msg);
  
          switch(msg.what){
  
              case (FALL1):
                  Log.d(TAG, "handleMessage: Fall 1");
                  SystemClock.sleep(3000);               
                  break;
              case (FALL2):
                  Log.d(TAG, "handleMessage: Fall 2");
                  break;
              default:
                  Log.e(TAG, "handleMessage: default kein passenden Wert gefunden"); //TODO in MainActivity Fehler anzeigen lassen
  
                  Log.e(TAG, "handleMessage: Error" );
                  break;
          }
      }
  }
  </code></pre>