Не могу понять, почему при нажатии кнопки приложение сворачивается
Написал симулятор гармони. Как оно выглядит. Сейчас хочу сделать для пользователей пример. Хочу при нажатии "кнопки 1" воспроизводить ноты и изменять текст на кнопках. Для этого создал новый класс MyTask, в нём поток и вызываю его из обработчика кнопки. Ещё на каждой кнопке висит обработчик, если пользователь хочет просто поиграть на гармошке. В симуляторе андроид студио всё работает. Когда запускаю на своем смартфоне, при нажатии "кнопки 1", приложение сворачивается и становиться не активным, но не закрывается и не виснет и его можно найти в списке запущенных программ и сделать активным. Может быть дело в версиях андроида и часть функций в моей версии андроида на смартфоне не поддерживается? Помогите тогда в этом вопросе разобраться.
По ссылке проект. https://cloud.mail.ru/public/j2tt/DA6Jaf8xt
Ниже код класса и функция его вызова: MyTask mt; class MyTask extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
//myButton1.setText("Begin");
}
@SuppressLint("WrongThread")
@Override
protected Void doInBackground(Void... params) {
try {
TimeUnit.MICROSECONDS.sleep(1);
time_nota = Integer.valueOf(String.valueOf(EditText1.getText()));
myButton3.setText("3");
myButton3.setBackgroundColor(0xFFE69B63);
streamID = sounds.play(b3,1.0f,1.0f,1,0,1);//Ми_1
TimeUnit.MILLISECONDS.sleep(time_nota);
sounds.stop(streamID);
myButton3.setText("Ми");
myButton3.setBackgroundColor(0xFFBBEEE7);
myButton6.setText("2");
myButton6.setBackgroundColor(0xFFE69B63);
streamID = sounds.play(b6,1.0f,1.0f,1,0,1);//Ля_1
TimeUnit.MILLISECONDS.sleep(time_nota);
sounds.stop(streamID);
myButton6.setText("Ля");
myButton6.setBackgroundColor(0xFFBBEEE7);
myButton5.setText("3");
myButton5.setBackgroundColor(0xFFE69B63);
streamID = sounds.play(b5,1.0f,1.0f,1,0,1);//Соль_1
TimeUnit.MILLISECONDS.sleep(time_nota);
sounds.stop(streamID);
myButton5.setText("Соль");
myButton5.setBackgroundColor(0xFFBBEEE7);
myButton6.setText("2");
myButton6.setBackgroundColor(0xFFE69B63);
streamID = sounds.play(b6,1.0f,1.0f,1,0,1);//Ля_1
TimeUnit.MILLISECONDS.sleep(time_nota);
sounds.stop(streamID);
myButton6.setText("Ля");
myButton6.setBackgroundColor(0xFFBBEEE7);
//такт2
myButton7.setText("4");
myButton7.setBackgroundColor(0xFFE69B63);
streamID = sounds.play(b7,1.0f,1.0f,1,0,1);//Си_1
TimeUnit.MILLISECONDS.sleep(time_nota);
sounds.stop(streamID);
myButton7.setText("Си");
myButton7.setBackgroundColor(0xFFBBEEE7);
myButton6.setText("2");
myButton6.setBackgroundColor(0xFFE69B63);
streamID = sounds.play(b6,1.0f,1.0f,1,0,1);//Ля_1
TimeUnit.MILLISECONDS.sleep(time_nota);
sounds.stop(streamID);
myButton6.setText("Ля");
myButton6.setBackgroundColor(0xFFBBEEE7);
myButton5.setText("3");
myButton5.setBackgroundColor(0xFFE69B63);
streamID = sounds.play(b5,1.0f,1.0f,1,0,1);//Соль_1
TimeUnit.MILLISECONDS.sleep(time_nota);
sounds.stop(streamID);
myButton5.setText("Соль");
myButton5.setBackgroundColor(0xFFBBEEE7);
myButton6.setText("2");
myButton6.setBackgroundColor(0xFFE69B63);
streamID = sounds.play(b6,1.0f,1.0f,1,0,1);//Ля_1
TimeUnit.MILLISECONDS.sleep(time_nota);
sounds.stop(streamID);
myButton6.setText("Ля");
myButton6.setBackgroundColor(0xFFBBEEE7);
//такт3
myButton5.setText("4");
myButton5.setBackgroundColor(0xFFE69B63);
streamID = sounds.play(b5,1.0f,1.0f,1,0,1);//Соль_1
TimeUnit.MILLISECONDS.sleep(time_nota*2);
sounds.stop(streamID);
myButton5.setText("Соль");
myButton5.setBackgroundColor(0xFFBBEEE7);
myButton4.setText("2");
myButton4.setBackgroundColor(0xFFE69B63);
streamID = sounds.play(b4,1.0f,1.0f,1,0,1);//Фа_1
TimeUnit.MILLISECONDS.sleep(time_nota);
sounds.stop(streamID);
//myButton4.setText("Фа");
myButton4.setBackgroundColor(0xFFBBEEE7);
//такт4
//myButton4.setText("2");
myButton4.setBackgroundColor(0xFFE69B63);
streamID = sounds.play(b4,1.0f,1.0f,1,0,1);//Фа_1
TimeUnit.MILLISECONDS.sleep(time_nota*3);
sounds.stop(streamID);
myButton4.setText("Фа");
myButton4.setBackgroundColor(0xFFBBEEE7);
TimeUnit.MILLISECONDS.sleep(time_nota);
} catch (InterruptedException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
//myButton1.setText("End");
}
}
public void button1(View view)
{
mt = new MyTask();
mt.execute();
}