Answer the question
In order to leave comments, you need to log in
How to leave the service after closing the application?
Hello, I'm making my first screen marker
and I need the overlay to remain even after closing the application, but so that I can enable / disable the overlay from a button in the application (if the application is open)
How can I implement this
I use
Intent overlayServiceIntent = new Intent(this, OverlayService.class);
bindService(overlayServiceIntent, overlayConnection, Context.BIND_AUTO_CREATE);
Intent overlayServiceIntent = new Intent(this, OverlayService.class);
stopService(overlayServiceIntent);
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.os.IBinder;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.Toast;
public class OverlayService extends Service {
Button overlayedButton;
WindowManager wm;
@Override
public IBinder onBind(Intent intent) {
Toast.makeText(this, "Hi", Toast.LENGTH_LONG).show();
wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
overlayedButton = new Button(this);
overlayedButton.setText("Overlay button");
WindowManager.LayoutParams params = new WindowManager.LayoutParams(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, PixelFormat.TRANSLUCENT);
wm.addView(overlayedButton, params);
return null;
}
public void onDestroy() {
super.onDestroy();
Toast.makeText(this, "Bye", Toast.LENGTH_LONG).show();
wm.removeView(overlayedButton);
overlayedButton = null;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question