简体   繁体   English

Android:在服务中使用Windowmanager显示视图是个好主意吗?

[英]Android: is it a good idea to display views with a windowmanager in a service?

I'm making a kind of minigame thats played in an android service, so the background is whatever you were doing on your phone at the time, the game starts when you click on the foreground notification. 我正在制作一种在android服务中播放的迷你游戏,因此背景是您当时在手机上所做的任何事情,当您单击前台通知时,游戏就会开始。 Everything is displayed with a windowmanager with the system_alert_window permission. 一切都由具有system_alert_window权限的windowmanager显示。 Im wondering if this is something thats a good thing to do or should this be only used for important things. 我想知道这是一件好事,还是仅用于重要的事情。 Would it be a better idea to start a transparent activity and display everything in there? 开始透明的活动并在其中显示所有内容是更好的主意吗?

This is actually how Facebook Messenger Chat Heads are implemented. 实际上,这就是Facebook Messenger聊天头的实现方式。

Functionally, there's nothing "wrong" with it as long as the user is expecting it. 从功能上讲,只要用户期望它,就没有什么“错”。 It could be rather jarring to have something interrupt them in the middle of a session with another app. 在与另一个应用程序进行会话的过程中,有一些事情打断他们可能会很不高兴。

The downside to implementing this is the Service (and corresponding alert) can be killed at any time. 实施此服务的缺点是可以随时终止服务(以及相应的警报)。 This in fact happens quite often with even Messenger. 实际上,甚至Messenger也经常发生这种情况。 Another app is in the foreground so it takes precedence over your game. 另一个应用程序位于前台,因此它优先于您的游戏。 Implementing it in a transparent activity would not be a way to overcome this. 在透明的活动中实施它不是克服此问题的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM