Monitor in-app changes

1

I need a class that listens for some change in the application (or external change).

I made a class that extended from class Service , however I realize that it enters the method onStartCommand only once.

Am I doing something wrong?

@Override
public IBinder onBind(Intent arg0) {
    return null;
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.e("--> ", "onStartCommand");
      return START_STICKY;
}

@Override
public void onDestroy() {
    super.onDestroy();
}
    
asked by anonymous 17.07.2017 / 04:55

1 answer

1

My suggestion is to create possible completion states (ok, error, etc.), or any other changes that you want to monitor, that an external service can generate at runtime and have the service store those values in a SharedPreferences according to the desired state, as it can be accessed in the Activity.

In the application you implement a SharedPreferences.OnSharedPreferenceChangeListener in your Activity and begin to "listen" the changes in the preference key specified above within the onSharedPreferenceChanged() method of that interface.

Further details on how to implement the official documentation: link

link

    
17.07.2017 / 14:47