【发布时间】:2012-12-29 11:08:56
【问题描述】:
我想知道当您从主要活动中创建广播接收器(在我的情况下为接近警报接收器)时会发生什么情况,并且应用程序进程由于某种未知原因而被终止?
我希望在我注册的广播接收器中接收我的接近警报,无论我的应用程序状态如何,这会发生还是我需要做一些特别的事情来确保这一点?
编辑澄清:
我必须从我的应用程序中注册接收器,而不是通过清单。由于我想要多个邻近警报,因此对于每个(不同的)位置,我需要动态创建接收器,因为我需要为每个位置注册接收器,并使用唯一的 id,不幸的是。
用于创建我的意图/待定意图/广播接收器的代码:
double latitude = location.getLat();
double longitude = location.getLon();
Intent intent = new Intent(PROX_ALERT_INTENT_ID);
PendingIntent proximityIntent = PendingIntent.getBroadcast(activity.getApplicationContext(), 0, intent, 0);
lm.addProximityAlert(
latitude, // the latitude of the central point of the alert region
longitude, // the longitude of the central point of the alert region
POINT_RADIUS, // the radius of the central point of the alert region, in meters
PROX_ALERT_EXPIRATION, // time for this proximity alert, in milliseconds, or -1 to indicate no expiration
proximityIntent // will be used to generate an Intent to fire when entry to or exit from the alert region is detected
);
IntentFilter filter = new IntentFilter(PROX_ALERT_INTENT_ID);
activity.registerReceiver(new ProximityIntentReceiver(location), filter);
【问题讨论】:
标签: android broadcastreceiver broadcasting