0
In Cassso this code makes a floating window with a button to end the activity, so as I do now to inflate in it a layout, or another way to build a layout within the service.
public class FloatingWindow extends Service {
    WindowManager wm;
    LinearLayout ll;
    @Override
    public IBinder onBind(Intent intent) {
        // TODO Auto-generated method stub
        return null;
    }
    @Override
    public void onCreate() {
        // TODO Auto-generated method stub
        super.onCreate();
        wm = (WindowManager) getSystemService(WINDOW_SERVICE);
        ll = new LinearLayout(this);
        ll.setBackgroundColor(Color.RED);
        LinearLayout.LayoutParams layoutParameteres = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT, 400);
        ll.setBackgroundColor(Color.argb(235,164,164,164));
        ll.setLayoutParams(layoutParameteres);
        final WindowManager.LayoutParams parameters = new WindowManager.LayoutParams(
                700, 600, WindowManager.LayoutParams.TYPE_PHONE,
                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                PixelFormat.TRANSLUCENT);
        parameters.gravity = Gravity.CENTER | Gravity.CENTER;
        parameters.x = 0;
        parameters.y = 0;
      Button     stop = new Button(this);
    stop.setText("Stop");
        ViewGroup.LayoutParams btnParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT);
        stop.setLayoutParams(btnParameters);
        ll.addView(stop);
        wm.addView(ll, parameters);
        ll.setOnTouchListener(new View.OnTouchListener() {
            WindowManager.LayoutParams updatedParameters = parameters;
            double x;
            double y;
            double pressedX;
            double pressedY;
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                switch (event.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        x = updatedParameters.x;
                        y = updatedParameters.y;
                        pressedX = event.getRawX();
                        pressedY = event.getRawY();
                        break;
                    case MotionEvent.ACTION_MOVE:
                        updatedParameters.x = (int) (x + (event.getRawX() - pressedX));
                        updatedParameters.y = (int) (y + (event.getRawY() - pressedY));
                        wm.updateViewLayout(ll, updatedParameters);
                    default:
                        break;
                }
                return false;
            }
        });
        stop.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                wm.removeView(ll);
                stopSelf();
                System.exit(0);
            }
        });
    }
    @Override
    public void onDestroy() {
        super.onDestroy();
        stopSelf();
    }
						
Try to explain better what you want. One of the main features of a service is not having layout (user interaction)
– ramaral
So what I want is a floating window, okay, with this code I already have, plus as it is a service has no layout, and I can’t and I don’t even know how to get this result.
– Wallace Roberto