Reputation: 2528
Im building an app on Xamarin.Android that plays music, for music playing im using a simple service.Even if the app is minimizes the service keeps playing music. For the communication between fragment and service i use MessageBus and i use Application class to store all the data that will be needed from many fragments until the App is closed.
I have a question about which is the best way to update the fragment on the OnResume event that the current playing track has change (after it was minimized and paused):
Im thinking one of those ways:
1) The Application class is storing the current playlists with the track name, resid etc and the current list position, so im thinking on the OnResume event of Application class to update the values and then on the OnResume event of the fragment to take the values from the Application class. But the problem is, how i can be sure that the application OnResume event will fire before fragment's same event?
2) The fragment on OnResume event to send a request to the service to get the current data and then to send them also to the Application class in order to be used from other fragments.
Which approach do you thik is the best?
Also is the same to use
public int listpos { get; set;}
instead of
private int listpos;
and to get or set the value with a function? I will have problems with the garbage collector with the public int or some other security issues?
Upvotes: 2
Views: 93
Reputation: 6181
One good approach would be to Bind
to the service and query it for the details when they are needed. I would not recommend setting any temporary data on the Application
class as this will force you to keep it in sync and can cause problems.
P.S. there is no OnResume
for the application as a whole.
Upvotes: 1