Rishabh jain
Rishabh jain

Reputation: 11

My app get stop when auto lock,how can it be sorted

package my.app.bhaktamar;
import android.app.Activity;
//import android.content.Intent;
import android.media.MediaPlayer;
//import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
//import android.view.View;

    public class MainActivity extends Activity {
        MediaPlayer dontcall;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Log.e("Pickle", "onCreate");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    protected void onResume() {
        Log.e("pickle", "onResume");
        dontcall = MediaPlayer.create(this, R.raw.gpad1);
        dontcall.start();
        super.onResume();
    }

    @Override
    protected void onPause() {
        Log.e("pickle", "onPause");
        dontcall.stop();
        dontcall.release();
        super.onPause();
    }
}

What should i do so sound should play after autolock ?

Upvotes: 1

Views: 68

Answers (2)

grig
grig

Reputation: 847

You need to use Service to play music background. If you want to play after autolock, use WakeLock.

Upvotes: 0

prakash
prakash

Reputation: 1413

use stop mediaplayer content in ondestroy() in your activity,so when your close activity after then the mediaplayer will stop.

@Override
public void onDestroy() 
{ 
    dontcall.stop();
    dontcall.release();
    super.onDestroy();
}

Upvotes: 1

Related Questions