0

I m trying to build a code to get position of the smartphone from a private SDK. So i m build this code:

nextomePhoenixSdk.getLocalizationLiveData().observe((LifecycleOwner) myActivity, new androidx.lifecycle.Observer(){

            public void onChanged(Object var1) {
                this.onChanged((NextomePosition)var1);
            }

            public final void onChanged(NextomePosition it) {
                Log.e("POSITION FROM NEXTOME", "X: " + it.getX() + " Y: " + it.getY());
            }
        });

Now if I try to start the application and I have myActivity as current View the new position will be notified by onChanged method.

But if I try to set in background my application or simply I try to change activity, the observer end to notify me new position though the service continue to run. Now I want to find a view to get new position every time also if the app is in background mode or if the user change the activity. How can I do this?

David Wasser
  • 93,459
  • 16
  • 209
  • 274
bircastri
  • 2,169
  • 13
  • 50
  • 119

1 Answers1

0

You are observing live data using a lifecycle observer that is tied to your Activitys lifecycle. When your Activity is stopped (covered, in background, etc.) you will no longer get any updates from the live data. That's exactly how this is supposed to work. Because your Activity is no longer visible, there is no point in passing any updates to it, because it can't show the data to the user. As soon as your Activity is visible again, you will continue to get live data updates.

This works exactly as intended.

David Wasser
  • 93,459
  • 16
  • 209
  • 274