检测'home键pressed'事件的android服务显示的用户界面(类似于Facebook的chatheads) [英] Detect 'home button pressed' event in android service displaying a UI (similar to facebook chatheads)

查看:220
本文介绍了检测'home键pressed'事件的android服务显示的用户界面(类似于Facebook的chatheads)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在facebook的chatheads,这是Facebook的Messenger的应用程序的一部分,我注意到以下行为: 据我所看到的,聊天头本身并打开聊天屏幕是一个服务的所有部分。无活动参与。

In facebook chatheads, that are part of the facebook messenger app, I noticed the following behavior: As far as I can see, the chat head itself and the opened chat screen are all parts of a service. No activity is involved.

怎么能确定? 之后我$打开聊天界面页上$ PSS的家,它就会被最小化回聊天的头,我可以马上重新打开聊天屏幕。如果聊天画面上是一个活动,然后再开始通过 startActivity活动(意向)Starting从HOME键$ P $后服务活动pssed无延时5秒

How can I be sure? After I press home on the opened chat screen, it gets minimized back to a chat head, and I can immediately reopen the chat screen. If the chat screen was an activity, then reopening the activity via startActivity(intent) after the home button was pressed, would delay the start of the activity, as specified here: Starting an activity from a service after HOME button pressed without the 5 seconds delay

这里:<一href="http://stackoverflow.com/questions/8163399/reason-for-5-sec-delay-to-show-an-activity-on-$p$pssing-the-home-button">Reason 5秒的延迟,显示在$ P $活动pssing home键?

在我的服务onCreate方法,我用下面的code,显示从服务中的用户界面:

in my service onCreate method, i use the following code to display a UI from service:

public class ServiceTest extends Service {
...
    @Override 
    public void onCreate() {
        super.onCreate();

        windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);

        WindowManager.LayoutParams params = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.TYPE_PHONE,
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
            PixelFormat.TRANSLUCENT);

        windowManager.addView(someView, params);
    }
....
}

有没有人有一个想法,我怎么能直接接收'pssed home键$ P $事件显示,从UI的服务?我想,当用户presses home键最大限度地减少我的观点(类似Facebook的聊天头)。

Does anyone have an idea how can I receive the 'home button pressed' event directly from a service displaying a UI? I would like to minimize my view (similar to facebook chat heads) when the user presses the home button.

推荐答案

在做我自己的研究有关问题好后,我带着得出以下结论:

well after doing my own research about that issue, I've came with the following conclusions:

Facebook的拦截的导航按钮,提供旗<一href="http://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#TYPE_SYSTEM_OVERLAY"><$c$c>TYPE_SYSTEM_OVERLAY属性。旁观这篇文章通过@jawsware提供的答案

Facebook "intercepting" the navigation buttons by providing the flag TYPE_SYSTEM_OVERLAY attribute. look on this post answer provided by @jawsware

在做什么,他通知:不要做 - 将导致影响控制,使其导航按钮

doing what he advices not to do - will lead to the "affect" of controling the navigation buttons

使用此标志提供专注于您的覆盖,并把焦点从后面的活动。

using this flag provides focus on your overlay, and takes the focus from the activity behind.

onFocusChangedListener 视图回调或的 OnKey听众它们发生反应,它与关闭叠加的全屏模式。

with the onFocusChangedListener view callback or the OnKey listener they reacts to it with closing the full screen mode of the overlay.

这也解释了他们如何反应,其从3导航按钮 - 家用/后退/最近的任务

that's also explains how they reacts to it from the 3 navigation buttons - home / back / recent tasks

这篇关于检测'home键pressed'事件的android服务显示的用户界面(类似于Facebook的chatheads)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆