0

How to click and send (Intent + putExtras + startActivity) in main activity (music preview activity) and playing song without showing it. Song list stays, but clicking list song --> refresh music preview activity. I want stay this activity (song list) but music priview activity get intent and refreshing and playing new song.

http://www.pixentral.com/pics/1MpvIjTXByBNfFasIZ0UFI2SbkS11.jpg http://www.pixentral.com/pics/1MpvIjTXByBNfFasIZ0UFI2SbkS11.jpg

song list :

public void onClick(View v) {

            Intent intent = new Intent(mContext, MusicPreview.class);
            intent.putExtra("pos", position).putExtra("names", SongsName).putExtra("songlist", SongsUri);
            mContext.startActivity(intent);

        }
Mike Laren
  • 8,028
  • 17
  • 51
  • 70
Farzad
  • 1,975
  • 1
  • 25
  • 47

1 Answers1

1

You could use a BroadcastReceiver for this.

private final BroadcastReceiver mHandleMessageReceiver = new BroadcastReceiver(){
        @Override
        public void onReceive(Context context, Intent intent) {
            //Get all your music data from the intent
            String position = intent.getStringExtra("pos");
            ...
        }
 };

Register this BroadcastReciever with an Intent in your NowPlayingActivity's onCreate() like this,

registerReceiver(mHandleMessageReceiver, new IntentFilter("songchange"));

And don't forget to unregister the receiver onDestroy().

unregisterReceiver(mHandleMessageReceiver);

And then in your PlaylistActivity on List item click do this,

Intent intent = new Intent("songchange");
intent.putExtra("pos", position);
...//pass all the needed data
sendBroadcast(intent);
siriscac
  • 1,699
  • 12
  • 21