расширяемый список показывает черный экран при втором запуске в моем приложении

#android #android-studio #android-fragments #expandablelistview

Вопрос:

Я создаю приложение с расширяемым списком, в котором я заставляю видео YouTube запускаться в полноэкранном режиме. Я пробовал другие решения, но это не сработало. Поэтому, когда я нажимаю элементы расширяемого списка, я связываю его с фрагментом поддержки в полноэкранном режиме, первый элемент работает хорошо, но когда я нажимаю кнопку «Назад» и нажимаю другой элемент, видео на YouTube падает, и экран становится черным. Таким образом, в основном, если я закрываю приложение YouTube или не включаю полноэкранный режим, элементы работают хорошо, поэтому я попробовал весь этот код, но он не сработал. Подсказка: это не API YouTube. А еще я перепробовал все эти коды

вот мое действие с расширяемым адаптером:

  @Override
public View getChildView (int i, int i1, boolean b, View view, ViewGroup viewGroup) {

    String listChild = (String) getChild(i, i1);

    // initialize view
    if (view == null) {
        LayoutInflater inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(R.layout.listitem, null);
    }
    // initialize and assign variables
    TextView child = view.findViewById(R.id.child);

    //set text on textview
    child.setText(listChild);
    //set on click listener


    child.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick (View view) {
            if (i == 0 amp;amp; i1 == 0) {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.youtube.com/watch?v=kISB5sum51Y"));
                intent.putExtra("force_fullscreen", true);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(intent);

            }
            if (i == 0 amp;amp; i1 == 1) {

                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.youtube.com/watch?v=dLDj2TTyMGM"));
                intent.putExtra("force_fullscreen", true);
                context.startActivity(intent);
            }
            if (i == 1 amp;amp; i1 == 0) {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.youtube.com/watch?v=ZuAzy1raPmE"));
                intent.putExtra("force_fullscreen", true);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(intent);
            }
            if (i == 1 amp;amp; i1 == 1) {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.youtube.com/watch?v=9bSsxmCguW8"));
                intent.putExtra("force_fullscreen", true);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(intent);
            }

        }
    });

    return view;
}
 

и вот манифест:

Вот расширенное представление :

     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context=".MainActivity">

    <ExpandableListView

        android:id="@ id/expandableListView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="16dp"
        />
</RelativeLayout>
 

вот список участников группы:

     <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="8dp"
    >
<TextView
    android:id="@ id/parent"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="?android:attr/expandableListPreferredChildPaddingLeft"
    android:padding="20dp"
    android:textSize="20sp"
    tools:ignore="MissingConstraints" />
</androidx.constraintlayout.widget.ConstraintLayout>
 

вот список :

     <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="55dp">
    <TextView
        android:id="@ id/child"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="5dp"
        android:paddingLeft="?android:attr/expandableListPreferredChildPaddingLeft"
        android:paddingBottom="5dp"
        android:textSize="23sp"
        tools:ignore="MissingConstraints" />
</androidx.constraintlayout.widget.ConstraintLayout>
 

вот приложение: https://i.stack.imgur.com/UFgc3.jpg

Комментарии:

1. Я думаю, что никто этого не знает 😒