我返回活动时如何重启Mediaplayer

时间:2015-06-03 17:13:27

标签: android lifecycle

我正在开发一款带音乐的应用。但是当我去另一个活动,然后回到上一个活动时,音乐不会重新开始,为什么?

 public class MaximosRegistros extends Activity {

ListView lista;
BaseDeDatos bd;
Vector<String> maxRegis;
MediaPlayer sonidoJuego;
Boolean sonido;
SharedPreferences sharedPref;
String puntos;
int pos;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maximos_registros);
    lista=(ListView)findViewById(R.id.lista);
    maxRegis= new Vector<String>();
    bd= new BaseDeDatos(this);
    maxRegis=bd.listaPuntos(10);
    TodoAdapter adaptador= new TodoAdapter(this,maxRegis);
    lista.setAdapter(adaptador);
    lista.setOnItemLongClickListener(new OnItemLongClickListener(){

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view,
                int position, long id) {
            pos=position;
            return false;
        }

    });
    registerForContextMenu(lista);
 }
 @Override
protected void onRestart() {
    // TODO Auto-generated method stub
    super.onRestart();

    sonidoJuego.start();
}
@Override
public boolean onContextItemSelected(MenuItem item) {
    // TODO Auto-generated method stub

    switch (item.getItemId()) {

    case R.id.compartir:
        Intent i = new Intent(this, EnviarPuntuacion.class);
        startActivityForResult(i, 1);
        break;

    }
    return super.onContextItemSelected(item);

}

我尝试使用onStart(),onPause(),onResume(),但它没有任何效果。 帮帮我!!

0 个答案:

没有答案