关闭事件中的Andr​​oid [英] Shutdown Events in Android

查看:105
本文介绍了关闭事件中的Andr​​oid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以拦截手机关机事件或者使用解决此不同的黑客攻击?我有一个始终运行的服务,是一个非市场应用程序,它正在收集一些分析数据的一部分。我想告诉的分析,以结束会话和报告,然后恢复系统关机。

Is it possible to intercept a phone shutdown event or perhaps use a different hack around this? I have an always running service that's part of a non-market application which is collecting some analytics data. I'd like to tell the analytics to end session and report, then resume the system shutdown.

我试图触发在的onDestroy或服务的onShutdown部分,但手机将关闭事件,而不给它时间报告。

I've tried triggering the event from the onDestroy or onShutdown parts of the services, but the phone will shutdown without giving it time to report.

工作围绕这基于活动的屏幕使得许多短会产生无意义的分析信息,我想避免的。

Working around this by making many short sessions based on the activity screens yields non-sensical analytics information that I'd like to avoid.

推荐答案

建立一个广播接收器捕捉ACTION_SHUTDOWN意图。

Build a broadcast receiver at catches the ACTION_SHUTDOWN intent.

在的onReceive()方法,你可以完成你正在做什么。

In the onReceive() method you can accomplish what you are trying to do.

<一个href="http://developer.android.com/reference/android/content/Intent.html#ACTION_SHUTDOWN">http://developer.android.com/reference/android/content/Intent.html#ACTION_SHUTDOWN

这篇关于关闭事件中的Andr​​oid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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