Communication between service and fragment and session data management

So guys here is my case
Im creating a Music player app with playlist.
Im in the process of designing the fragment that will control the Music and i have 3 cases that i want TO discuss with you guys about how TO handle the audio playback and the display of the playlist.
I have a listfragment which has a list that works as a playlist, 3 buttons that change the playlist and a background service that is displaying the audio.so what i want TO discuss is this:
1) sending the data To the service.
2) sending data from the service To the fragment.
3) handling displayed data on the fragment when the fragment is paused / killed.
The data im talking about could be:
A) a list with song names and ids
B)the current song name theme name album image
C)the position int of the playlist.
For all the above i want To ask some questions about how TO handle each case.
My initial plan was To use public list accessible from both fragment and service but that might not BE a good idea because i have read that the garbage collector might destroy those lists.is that true?
I have read most of the XAmarin guides com many articles and from what i have read i have those options:
i) use public classes.
ii)use intent TO send data.
iii)use sharedpreferences or sql TO retrieve data.
iv)use broadcast reciever TO send data.
The option i is what im doing now.
For the case 1 i need TO send TO the service all the data.should i use intent? Should i keep using public lists or should i retrieve the data from sql or sharedpref?what is the best approach.
About the case 2 i think the best approach is broadcastrec. Because IT will send the data and If the fragment is not shown the data will BE ignored which is OK.
About case 3, the fragment might get distroyed and need TO BE created again so i need TO create the list,get the current category and list position.for those data im thinking to reproduce them on oncreateview and on onupdate by extracting them from sharedpref except the list that will get IT from sql.
For all those cases which is the best approach, please advice, thanks.

Posts

  • CheesebaronCheesebaron DKInsider, University mod

    Do you expect us to read that un-formatted piece of text?

  • ChristopherDrososChristopherDrosos GRMember ✭✭

    i have format it. Im from mobile i dont know what happens.i cant edit it. My device is sony w580 :) pretty old

  • ChristopherDrososChristopherDrosos GRMember ✭✭
    edited September 2014

    @Cheesebaron‌ Here is my post again:

    So guys here is my case.

    Im creating a Music player app with playlist.

    Im in the process of designing the fragment that will control the Music and i have 3 cases that i want to discuss with you guys about how to handle the audio playback and the display of the playlist.

    I have a listfragment which has a list that works as a playlist, 3 buttons that change the playlist and a background service that is displaying the audio.so what i want to discuss is this:

    1) sending the data To the service. 
    
    2) sending data from the service To the fragment.
    
    3) handling displayed data on the fragment when the fragment is paused / killed. 
    

    The data im talking about could be:

    a) a list with song names and ids 
    
    b) the current song name theme name album image 
    
    c) the position int of the playlist. 
    

    For all the above i want To ask some questions about how to handle each case. My initial plan was To use public list accessible from both fragment and service but that might not be a good idea because i have read that the garbage collector might destroy those lists.

    Is that true?

    I have read most of the Xamarin guides com many articles and from what i have read i have those options:

    i) use public classes. 
    
    ii) use intent to send data. 
    
    iii) use sharedpreferences or sql to retrieve data.
    
     iv) use BroadcastReceiver to send data. 
    

    The option i is what im doing now.

    For the case 1 i need to send to the service all the data.should i use intent? Should i keep using public lists or should i retrieve the data from sql or sharedpref?what is the best approach.

    About the case 2 i think the best approach is BroadcastReceiver. Because it will send the data and If the fragment is not shown the data will be ignored which is OK.

    About case 3, the fragment might get distroyed and need to be created again so i need to create the list, get the current category and list position. for those data im thinking to reproduce them on oncreateview and on onupdate by extracting them from sharedpref except the list that will get it from sql.

    For all those cases which is the best approach, please advice, thanks.

    (Why it is so hard on this forum to format the messages? enters are ignored, bold is not working..)

  • ChristopherDrososChristopherDrosos GRMember ✭✭
    edited September 2014

    If i try to set a list of objects with a public class like in this app https://github.com/chrisntr/DaysUntilXmas/blob/master/Android/DaysUntilXmasAndroid/Helpers/Music.cs and then use it like this:

    ...
    private MusicOptions musicOptions = new MusicOptions ();
    ...
    musicOptions.MusicItems [track].ResId = ID;
    

    Is this method of storying variables safe?

    I mean what if the android is low on memory and the garbage collector start deleting things? Your variables will stay intact? Should i better send the Lists with intent?

Sign In or Register to comment.