title: slow opening an opened activity with FLAG_ACTIVITY_SINGLE_TOP
body: <p>I'm trying to use a floating widget that pops up when onPause is invoked and relaunch the activity when clicked , I used FLAG_ACTIVITY_SINGLE_TOP so it will not start a new activity , but it takes a lot of time to show the activity if it was already opened.</p>
  
  <pre><code>package com.example.myapplication;
  
  public class MainActivity extends AppCompatActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          askForSystemOverlayPermission();
      }
  
      private void askForSystemOverlayPermission() {
          if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.M &amp;&amp; !Settings.canDrawOverlays(this)) {
              Log.d("mmm", "asking permission");
              Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                      Uri.parse("package:" + getPackageName()));
              startActivityForResult(intent, 1);
          }
      }
  
      @Override
      protected void onPostResume() {
          super.onPostResume();
          stopService(new Intent(this, MyService.class));
      }
  
      @Override
      protected void onPause() {
          super.onPause();
          if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.M &amp;&amp; Settings.canDrawOverlays(this) || Build.VERSION.SDK_INT &lt; Build.VERSION_CODES.M) {
              startService(new Intent(this, MyService.class));
          }
      }
  }
  
      package com.example.myapplication;
  
  public class MyService extends Service {
  
      private WindowManager manager;
      private ImageView v;
  
      @SuppressLint("ClickableViewAccessibility")
      @Override
      public void onCreate() {
          super.onCreate();
          v = new ImageView(this);
          v.setImageResource(R.drawable.ic_launcher_background);
          manager = (WindowManager) getSystemService(WINDOW_SERVICE);
          v.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  GoToActivity();
              }
          });
          WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                  150, 150,
                  WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
                  WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                  PixelFormat.TRANSLUCENT);
  
  
          manager.addView(v, params);
  
          v.setOnTouchListener(new View.OnTouchListener() {
              float dX;
              float dY;
              int lastAction;
  
              @Override
              public boolean onTouch(View v, MotionEvent event) {
                  WindowManager.LayoutParams layoutParams = (WindowManager.LayoutParams) v.getLayoutParams();
                  switch (event.getActionMasked()) {
                      case MotionEvent.ACTION_DOWN:
                          dX = layoutParams.x - event.getRawX();
                          dY = layoutParams.y - event.getRawY();
                          lastAction = MotionEvent.ACTION_DOWN;
                          break;
  
                      case MotionEvent.ACTION_MOVE:
                          layoutParams.y = (int) (event.getRawY() + dY);
                          layoutParams.x = (int) (event.getRawX() + dX);
                          manager.updateViewLayout(v, layoutParams);
                          lastAction = MotionEvent.ACTION_MOVE;
                          break;
  
                      case MotionEvent.ACTION_UP:
                          if (lastAction == MotionEvent.ACTION_DOWN)
                              break;
  
                      default:
                          return false;
                  }
                  return false;
              }
          });
      }
  
  
      private void GoToActivity() {
          Intent i = new Intent(this, MainActivity.class);
          i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
          stopSelf();
          startActivity(i);
      }
  
      @Override
      public void onDestroy() {
          super.onDestroy();
          manager.removeView(v);
      }
  
      @Nullable
      @Override
      public IBinder onBind(Intent intent) {
          return null;
      }
  }
  </code></pre>