Hi guys and girls (of course)
I have this situation: I have running a service in the background and a foreground activity, and I hope that at a specific time the activity executes a method on demand of the service.
What I have done: Well the solution I have given is something almost to brute force. The service writes a value in the preferences, and the activity that is controlling that value every 100 mS, because I need it to be the instantaneous update; When you see the change in value, execute the method
Problem with this solution is that it consumes enough resources and does not always run as it should
Any ideas?
EDITED
This is part of the code I've done
1-in the service
//...
if (needAct)
PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean("needAct", true).commit();
///...
2-in the onCreate of the activity
///...
timerUiUpdate.schedule(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean("needAct", false)){
//hacer lo que quiero hacer para actualizar la Activity
}
}
});
}
}, 100, 100);
///...