I ran into some problems trying to transmit data through intentions and while awaiting BroadcastReceiver intentions regarding proximity alerts. In particular, I am trying to convey an object that, among other things, constantly changes the user's position. I tried the various tactics offered here (and not only), but no one worked, which led to either zero values ββor the same as the first created intentions, when the intention was received on the side of BroadcastReceiver. Tactics Used:
- Mark the intention that the object bears: FLAG_ACTIVITY_NEW_TASK + FLAG_ACTIVITY_CLEAR_TOP + FLAG_ACTIVITY_SINGLE_TOP Result: Zero values ββon the BroadacastReceiver side.
- A mark of the pending intent created using the original intent, with: FLAG_UPDATE_CURRENT or FLAG_CANCEL_CURRENT Result: Zero values ββon the BroadacastReceiver side.
- Getting a random identifier for an intent or pending intent using System.currentTimeMillis (); Result: intentions do not start or are not accepted at all
- Nothing is described above. Result: getting the same initial value every time.
Code for the calling method (devoid of any experiments / creating null values):
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);
Code for the calling method that sets the intent filter and registers the BroadcastReceiver:
public void addNewCarPoint (MyCar myCar){ IntentFilter filter = new IntentFilter(myCar.getMyCarName()); registerReceiver(new ProximityAlertReceiver(), filter); setProximityAlert(myCar); }
Code for BroadcastReceiver side:
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);
}
Any ideas would be more than welcome. Thank you in advance.
source share