I currently have a service running in the background to access location properties such as latitude and longitude. Every time the service OnLocationChange hits, i send the data into a broadcast receiver. The broadcast receiver class waits and receives the latitude and longitude and stores them nicely as doubles.
I now want to access the two doubles from the broadcast receiver class. I've tried Get and Set methods but the data always passes through as null or 0.
This is my default Receiver class without any get set methods implemetned:
[BroadcastReceiver(Enabled = true)]
[IntentFilter(new[] { "GpsReceiever" })]
public class GPSReceiver : BroadcastReceiver
{
public double latData;
public double longData;
public double altData;
public float accData;
public override void OnReceive(Context context, Intent intent)
{
latData = intent.Extras.GetDouble("lat");
longData = intent.Extras.GetDouble("long");
altData = intent.Extras.GetDouble("alt");
accData = intent.Extras.GetFloat("acc");
}
}
Am i able to pass the data through to another class? and if so how would i go about it?
Thank you for your time!
There are a couple of options.
Please also read: Broadcast receiver's life cycle
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.