private static void sendMessageToActivity(Location l, String msg) {
Intent intent = new Intent("GPSLocationUpdates");
intent.putExtra("Status", msg);
Bundle b = new Bundle();
b.putParcelable("Location", l);
intent.putExtra("Location", b);
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
}
sendMessageToActivity(location, "location");
LocalBroadcastManager.getInstance(context).registerReceiver(
mMessageReceiver, new IntentFilter("GPSLocationUpdates"));
private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String message = intent.getStringExtra("Status");
Bundle b = intent.getBundleExtra("Location");
Location lastKnownLoc = (Location) b.getParcelable("Location");
if (lastKnownLoc != null) {
latitude=lastKnownLoc.getLatitude();
longitude=lastKnownLoc.getLongitude();
Log.e("TAG", "Fragments Maps: "+ lastKnownLoc.getLatitude() + "\n longitude="+lastKnownLoc.getLongitude() );
}
}
};