BlackBlind567 / Location_Updates-Background_Foreground

74 stars 33 forks source link

How to get value distance on background process since service will stop in background process #4

Open hafiz013 opened 5 years ago

hafiz013 commented 5 years ago

private void onNewLocation(Location location) { Log.d(TAG, "New location: " + location);

    mLocation = location;

    // Notify anyone listening for broadcasts about the new location.
    Intent intent = new Intent(ACTION_BROADCAST);
    intent.putExtra(EXTRA_LOCATION, location);
    LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(intent);

    // Update notification content if running as a foreground service.
    if (serviceIsRunningInForeground(this)) {
        mNotificationManager.notify(NOTIFICATION_ID, getNotification());

        // Getting location when notification was call.
        latitude = location.getLatitude();
        longitude = location.getLongitude();

        // Here using to call Save to serverMethod
        SavetoServer();

    }
}

could u explain how to get value when the apps in background process?

BlackBlind567 commented 5 years ago

In if condition is checking your app is in foreground or background after that it runs a method.

hafiz013 commented 5 years ago

@BlackBlind567 hi do u know how to check this service already run regardless background or foreground in main activity?