0

I am trying to download an mp3 file. For this i have created an activity like this:

public class audiostream extends Activity{

private Button streamButton;

private ImageButton playButton;

private TextView textStreamed;

private boolean isPlaying;

private StreamingMediaPlayer audioStreamer; //This is the object of supporting class

protected void onCreate(Bundle savedInstanceState){

        super.onCreate(savedInstanceState);
            //other activities                     }

now on the button click event i am calling this function:

private void startStreamingAudio() {
        try { 
            final ProgressBar progressBar = (ProgressBar) findViewById(R.id.progress_bar);
            if ( audioStreamer != null) {
                audioStreamer.interrupt();
            }
            audioStreamer = new StreamingMediaPlayer(this,textStreamed, playButton, streamButton,progressBar);
            audioStreamer.startStreaming("file path",file_size,duration);

            streamButton.setEnabled(false);
        } catch (IOException e) {

        }

    }

Give below is the StreamingMediaPlayer class:

public class StreamingMediaPlayer {


    private TextView textStreamed;

    private ImageButton playButton;

    private ProgressBar progressBar;
    public StreamingMediaPlayer(Context  context,TextView textStreamed, ImageButton playButton, Button  streamButton,ProgressBar    progressBar) 
        {
        this.context = context;
        this.textStreamed = textStreamed;
        this.playButton = playButton;
        this.progressBar = progressBar;
       }

}

Rest of the works are done by the remaining class such as incrementing the progress bar, playing the audio etc.

Progress bar increments as audio progresses. The issue that i am facing is that, while playing the audio, if i am pressing back button and opening previous activity the audio plays (this is what i want), but when i come back to the activity with the help of intent, everything appears in a way that activity is just created. The progress bar which was previously progressing now looks when i first opened this activity. In simple sentence the problem is that, the activity which is playing the audio file is not resuming the previous state. Kindly help me.

roy mathew
  • 7,782
  • 4
  • 29
  • 40

2 Answers2

1

The parameter of onCreate(savedInstance) is precisely designed to save the state of an activity. See Saving Android Activity state using Save Instance State

Community
  • 1
  • 1
rds
  • 26,253
  • 19
  • 107
  • 134
0

in the activity-lifecycle you have to catch the onResume() Intent and fill your data accordingly.

Peter Miehle
  • 5,984
  • 2
  • 38
  • 55
  • As the main control is with another class, i am exactly not sure how to bring back the previous state of control in the onResume() – roy mathew Jan 31 '12 at 14:05