简体   繁体   English

退出应用程序后(即按下主屏幕按钮),Android ProximityAlert无法保持活动状态

[英]Android ProximityAlert does not stay active after exiting app (i.e. pressing home button)

I am able to set a proximity alert (ie generates a notification when the phone enters/exits specified radius) which works as I want only when I still have the app up. 我能够设置一个接近警报(即,当手机进入/退出指定半径时生成通知),仅当我仍然有该应用程序时,它才能按我希望的方式工作。 When I click home, the radius exit/enter conditions which normally fire the alert do not result in a notification. 当我单击“主页”时,通常会触发警报的半径退出/进入条件不会产生通知。

I am pretty sure it has something to do with registering and unregister receivers, but I cannot figure it out. 我很确定这与注册和注销接收者有关,但是我无法弄清楚。 When I don't include a call to unregisterReceiver and press home, a leaked receiver error appears. 当我不包含对unregisterReceiver的呼叫并按home键时,会出现泄漏的接收器错误。 When I include it in onPause() and click home, I get no errors, but the alert doesn't work. 当我将其包含在onPause()中并单击“主页”时,我没有收到任何错误,但警报不起作用。

Is there something I am not understanding about these proximity alerts? 关于这些接近警报,我是否不了解? What is the best way to have an app respond to proximity as I wish it to? 让应用程序按我希望的方式响应距离的最佳方法是什么?

Register your BroadcastReceiver in the Manifest file. 在清单文件中注册您的BroadcastReceiver。 It will automatically register and unregister itself. 它将自动注册和注销自己。

<receiver android:name="ProximityIntentReceiver">
    <intent-filter>
        <action android:name="com.example.googlemaps.PROXIMITY_ALERT">
    </intent-filter>
</receiver> 

It will work even after the home button is pressed. 即使按下主页按钮,它也将起作用。

Register pending intent instead of receiver. 注册挂起的意图,而不是接收者。 They survive application shutdown 它们在应用程序关闭后仍能生存

暂无
暂无

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

相关问题 在启动画面期间按下主页按钮几秒钟后Android应用程序会打开 - Android app opens after a few seconds after pressing home button during splash screen 按主页按钮后如何在android中隐藏键盘 - How to hide keypad in android after pressing home button 在平板电脑上自动更新 Android App(即没有市场!) - Automatically update Android App on Tablet (i.e. without Market!) Android 条码扫描器应用程序,按下扫描按钮后相机不打开 - Android barcode scanner app ,after pressing the scan button the camera does not open 即使按下主屏幕按钮或后退按钮,Android应用程序也会重新打开并继续进行下一个活动 - Android app reopening and proceeding on the next activity even when pressing the home button or back button 按下录制按钮后,录制开始并立即停止在 Android App 中 - After pressing record button recording starts and instantly stops in Android App 在 android 中按下主页按钮后,如何保持 webview 在前台服务中运行? - How to keep webview running in foreground service after pressing home button in android? 单击按钮后(即在执行操作之后)更改按钮的背景 - Changing the Background of a button after it is clicked (i.e. after Action performed) 如何检查网址的域名是否处于活动状态(即未过期)? - How to check if a domain name of a url is active or not(i.e. not expired)? 当Android应用程序不再处于活动状态时,位置更新保持活动状态 - Locations updates stay active when Android app is not longer active
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM