I am trying to launch a window when an action is executed on my app. The problem of this scheme can sometimes be executed in the background, which is why sometimes I will have to launch it without an activity:
I am running this fragment:
public void alertaSubscriptor(String titulo,String mensaje) {
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
| WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
PixelFormat.TRANSPARENT);
final WindowManager wm = (WindowManager) MOCA.getApplicationContext().getSystemService(WINDOW_SERVICE);
LayoutInflater inflater = (LayoutInflater) MOCA.getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View myView = inflater.inflate(R.layout.ventanaemrgente, null);
myView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.d(TAG, "touch me");
wm.removeViewImmediate(v);
return true;
}
});
// Add layout to window manager
wm.addView(myView, params);
}
But in the background it does not run
02-16 09: 33: 07.140 31071-32472 / com.procibernetica.moca W / MessageQueue: Handler (android.view.Choreographer $ FrameHandler) {21c0847c} sending message to a Handler on a dead thread java.lang.RuntimeException: Handler (android.view.Choreographer $ FrameHandler) {21c0847c} sending message to a Handler on a dead thread at android.os.MessageQueue.enqueueMessage (MessageQueue.java:336) at android.os.Handler.enqueueMessage (Handler.java:626) at android.os.Handler.sendMessageAtTime (Handler.java:595) at android.view.Choreographer $ FrameDisplayEventReceiver.onVsync (Choreographer.java:751) at android.view.DisplayEventReceiver.dispatchVsync (DisplayEventReceiver.java:139) at android.os.MessageQueue.nativePollOnce (Native Method) at android.os.MessageQueue.next (MessageQueue.java:138) at android.os.Looper.loop (Looper.java:131) at android.os.HandlerThread.run (HandlerThread.java:61)
How could I throw a window or a bubble as a messenger, when the activity is in the background?