android - Sharing music Service with 2 activities -


i have fragment[1] plays music service , shows progress of song duration,songname etc. when click of albumart of song played, need show screen[2] music playing in same service , progress. passing values [1] [2], using intent .but both [1] , [2] not in sync.how make [1] , [2] both show , play same song,duration etc. changes should make in [1] , [2] both. calling service class in both [1] , [2]. edit creating service both in [1] , [2]. right way it?

code in [1] :

imgalbumart.setonclicklistener(new onclicklistener() {          @override         public void onclick(view v) {             intent testintent = new intent(getactivity(),playscreen.class);             testintent.putextra("currentdur",currentduration);             testintent.putextra("totaldur",totalduration);             testintent.putextra("progress",progress);               startactivity(testintent);          }     }); 

edit tried using broadcast receiver.

 public class musicintentreceiver extends broadcastreceiver { @override public void onreceive(context context, intent intent) {      if(intent.getaction().equals("test"))     {          bundle = intent.getextras();           string title = extra.getstring("title");          log.d("receiver","boradcast receieved wt title"+title);      } 

now how use title value in [2]???

you don't need share data between fragments , need 1 playerservice holds player info , publish info subscriber want fragments or activities.

to publish info use broadcastreceiver or if want learn more powerfull recomend observable class of rxjava.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -