So thanks to @Mohammadreza I used sharedPref on the service intent and its worked.
This is what I did:
public static final String MY_PREFS_NAME = "MyData";
//Save SharedPref(BackgroundActivity):
SharedPreferences.Editor editor = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE).edit(); editor.putString("AddressBackgound",mAddress); editor.putString("AddressLatBackgound", String.valueOf(destinationLat)); editor.putString("AddressLngBackgound", String.valueOf(destinationLng)); editor.apply();
//Read SharedPref(MapsActivity):
SharedPreferences prefs = getSharedPreferences(BackgroundLocation.MY_PREFS_NAME, MODE_PRIVATE);
BackgroundLocation backgroundLocation = new BackgroundLocation();
if (isMyServiceRunning(backgroundLocation.getClass()) && prefs != null ) { String mAddress = prefs.getString("AddressBackgound","mAddress"); Double UserStartLocationLat = Double.parseDouble(String.valueOf(Double.valueOf(prefs.getString("UserStartLocationLat", "UserStartLocationLatNull")))); Double UserStartLocationLng = Double.parseDouble(String.valueOf(Double.valueOf(prefs.getString("UserStartLocationLng", "UserStartLocationLngNull")))); }
isMyServiceRunning:
private boolean isMyServiceRunning(Class<?> serviceClass) { ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { if (serviceClass.getName().equals(service.service.getClassName())) { Log.i ("Service status", "Running"); return true; } } Log.i ("Service status", "Not running"); return false;}