我正在所有应用程序上面创建浮动视图,但每次使用该服务将视图添加到窗口管理器崩溃时(由于设备上的内存问题或其他),视图都会被删除。我返回START_STICKY以便立即再次添加,但有没有办法将其保留在屏幕上,因为闪烁不是很吸引人。
代码onStartCommand()
final ImageView container = new ImageView(getApplicationContext());
final WindowManager.LayoutParams params = new WindowManager.LayoutParams(WindowManager.LayoutParams.WRAP_CONTENT,
SettingsUtil.getFloaterSize(), WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED + WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
+ WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE + WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN, PixelFormat.TRANSLUCENT);
((WindowManager) getSystemService(Context.WINDOW_SERVICE)).addView(container, params);
`