0

I have a floating button being drawing using android.permission.SYSTEM_ALERT_WINDOW above all the windows , what am trying to accomplish is once I press on it , I start ProjectionMedia API here is what am doing :

//passing to it the Main activity
  public MyManager(Activity activity) {
        this.activity = activity;
        // call for the projection manager
        mProjectionManager = (MediaProjectionManager) activity.getSystemService(Context.MEDIA_PROJECTION_SERVICE);
    }

 public void Capture() {
        isWorking = true;
        mHandler = new Handler();
        Intent i = mProjectionManager.createScreenCaptureIntent();
       // i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        activity.startActivityForResult(i, REQUEST_CODE);

    }

and in MainActivity I have static MyManager so I can accesses it from within the service , but once I call Capture from the Service the app doesn't do anything , and there is nothing in the logact , what I'm missing here?

Abanoub
  • 3,623
  • 16
  • 66
  • 104

1 Answers1

-1

First, you are leaking the memory associated with that activity and everything it references (views, content in those views, etc.).

Second, once the activity is destroyed, you cannot use it anymore, such as for things like startActivityForResult().

You need to do the whole startActivityForResult() work from your activity before showing your floating window. See this sample app, where I use a Notification instead of a floating window.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491