Colleagues, maybe someone came across, on the emulator the application works fine, and when I install app-debug.apk on the phone, the buttons do not work in the application, the buttons do not even respond to the finger.

Markup:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="111dp" android:layout_marginBottom="8dp" android:layout_marginEnd="8dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:orientation="horizontal" android:padding="16dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.0" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.017"> 

Code:

  @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); img_play = (ImageButton) findViewById(R.id.img_play); img_play.setEnabled(false); mediaPlayer = new MediaPlayer(); mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); new PlayerTask().execute(stream); img_play.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (flag) img_play.setImageResource(R.drawable.pause); else img_play.setImageResource(R.drawable.play); flag = !flag; if (started) { started = false; mediaPlayer.pause(); } else { started = true; mediaPlayer.start(); } } }); } 

Manifesto

 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="horoshoe.radio.online"> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.INTERNET"/> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> 

After removing img_play.setEnabled(false); On the phone, the application crashes, and on the emulator it continues to work

java.lang.RuntimeException: an error occurred while executing doInBackground () at android.os.AsyncTask $ 3.done (AsyncTask.java.38) at java.util.concurrent.FutureTask.finishCompletion (FutureTask.java;54) at java. util.concurrent.FutureTask.setException (FutureTask.java:223) at java.util.concurrent.FutureTask.run (FutureTask.java:242) at android.os.AsyncTask $ SerialExecutor $ 1.run (AsyncTask.java:243) at java.util. Caused by: java.lang.IllegalStateException at android.media.MediaPlayer._prepare (Native Method) at android.media.MediaPlayer.prepare (MediaPlayer.java:1188) at horoshoe.radio.online.MainActivity $ PlayerTask.doInBackground (MainActivity. java: 71) at horoshoe.radio.online.MainActivity $ PlayerTask.doInBackground (MainActivity.java:65) at android.os.AsyncTask $ 2.call (AsyncTask.java:304) at java.util.conc urrent.FutureTask.run (FutureTask.java:237)

  • Show logs, manifest, xml with markup and code where you assign OnClickListener . What is targetSdkVersion? - Suvitruf
  • To add to make changes to the question itself. The markup, by the way, did not lead all. And you also need AndroidManifest.xml content - Suvitruf
  • Try removing this line of code here: img_play.setEnabled (false); - Vitaly Tomashevsky
  • I added to the general question that I cannot figure out how to add pieces of code here, more than 600 characters. - Michael
  • @ Michael I corrected the question and answered ^ _ ^ - Suvitruf

1 answer 1

In general, I thought so. Probably the case is supportsRtl="true" .

If you look at the official documentation :

Declares whether your application is right-to-left (RTL) layouts.

RTL layouts. If you targetSdkVersion to make it , you’ll always be able to make it your choice. -to-right).

The default value of this attribute is false .

This attribute was added in API level 17 .

It is necessary to impose with an eye on this flag. For starters, try removing this flag and seeing. If everything is normal on the device, then you need to think about how to change the markup.

  • Changed to supportsRtl = "false", but still crashes on the device. - Michael
  • @Mikhail fall is different. What do you have on line 71 in MainActivity ? If mp.prepare(); then replace with mp.prepareAsync(); - Suvitruf
  • Thanks, I changed the prepere to prepareAsync, the application started, the button works, but there is no sound. - Michael
  • @ Michael is another problem. Ask a separate question (: - Suvitruf
  • OK. Thanks for clarifying. - Michael