近接アラートに関して、インテントおよび保留中のインテントを介してデータを BroadcastReceiver に渡そうとするときに、いくつかの問題に直面しています。より具体的には、特にユーザーの絶えず変化する位置を保持するオブジェクトを渡そうとしています。ここで提案されているさまざまな戦術を試しましたが (それだけではありません)、どれも機能せず、BroadcastReceiver 側でインテントが取得されると、null 値または最初に作成されたインテントと同じ結果になりました。使用された戦術:
- FLAG_ACTIVITY_NEW_TASK+FLAG_ACTIVITY_CLEAR_TOP+FLAG_ACTIVITY_SINGLE_TOP 結果:BroadacastReceiver 側の Null 値で、オブジェクトを運ぶインテントにフラグを立てます。
- FLAG_UPDATE_CURRENT または FLAG_CANCEL_CURRENT 結果: BroadacastReceiver 側の Null 値を使用して、初期インテントを使用して作成された保留中のインテントにフラグを立てる
- System.currentTimeMillis(); を使用して、インテントまたは保留中のインテントのランダム ID を取得します。結果: インテントが起動されない、またはまったく受信されない
- 上記の説明はありません。結果:毎回同じ初期値を取得。
呼び出しメソッドのコード (すべての実験/null 値の生成から削除):
private void setProximityAlert(MyCar myCar) {
String locService = Context.LOCATION_SERVICE;
LocationManager locationManager;
locationManager = (LocationManager)getSystemService(locService);
float radius = myCar.getMyCarRadius();
long expiration = myCar.getMyCarExpiration();
myService.setMyDriverLat(userLat);//setting user's position
myService.setMyDriverLng(userLng);//setting user's position
Intent intent = new Intent(myCar.getMyCarName());
intent.putExtra("myCar",myCar);
PendingIntent proximityIntent = PendingIntent.getBroadcast(this, -1, intent, 0);
locationManager.addProximityAlert(myCar.getMyCarLat(), myCar.getMyCarLng(), radius, expiration, proximityIntent);
}
インテント フィルタを設定し、BroadcastReceiver を登録する呼び出しメソッドのコード:
public void addNewCarPoint (MyCar myCar){
IntentFilter filter = new IntentFilter(myCar.getMyCarName());
registerReceiver(new ProximityAlertReceiver(), filter);
setProximityAlert(myCar);
}
BroadcastReceiver 側のコード:
public class ProximityAlertReceiver extends BroadcastReceiver {
@Override
public void onReceive (Context context, Intent intent) {
MyCar myCar=(MyCar)intent.getParcelableExtra("myCar");
driverLoc=(String)Double.toString(myCar.getMyDriverLat());
Toast.makeText(context, userLoc, Toast.LENGTH_SHORT).show();
Intent i = new Intent(context, MyCarDiscoveryPrompt.class);
context.startActivity(i);//firing intent
}
public void intentDataLoader(){
}
}
どんなアイデアでも大歓迎です。前もって感謝します。