メイン アクティビティ内からブロードキャスト レシーバー (私の場合は近接アラート レシーバー) を作成し、アプリ プロセスがなんらかの理由で強制終了されるとどうなるでしょうか?
アプリの状態に関係なく、登録したブロードキャストレシーバーで近接アラートを受信したいのですが、それは起こりますか、それとも確実にするために何か特別なことをする必要がありますか?
明確にするために編集:
マニフェスト経由ではなく、アプリ内からレシーバーを登録する必要があります。複数の近接アラートが必要なため、(さまざまな) 場所ごとに受信者を動的に作成する必要があります。残念ながら、一意の 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);