Screen Freezes in Black Before Animation List Initializing

I have animation-list code. It is okey for android 5.x and 9 but when I try the app by using android 8.1 and 6.1 it has black screen for 5-10 second before animation-list start. How to avoid it.

My java code:

package com.edulab.akiciokuma;  import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import android.content.Intent; import android.graphics.drawable.AnimationDrawable; import android.media.MediaPlayer; import android.os.Bundle; import android.os.Handler; import android.widget.ImageView; import android.widget.Toast; import com.google.android.gms.tasks.OnCompleteListener; import com.google.android.gms.tasks.Task; import com.google.firebase.firestore.DocumentSnapshot; import com.google.firebase.firestore.FirebaseFirestore;  public class AnimationActivity extends AppCompatActivity {  private MediaPlayer player; private AnimationDrawable running; private ImageView anime; private String  animwhich, strategy, condition; private int level; private FirebaseFirestore firebaseFirestore =  FirebaseFirestore.getInstance(); private String[] animalIntro = {"tosbaameeting", "zipzipintro",  "foxintro", "atintro", "deveintro", "cheetahintro"}; private String[] animalModel = {"tosbaamodel", "zipzipmodel",  "foxmodel", "atmodel", "devemodel", "cheetahmodel"}; private String[] animalModel2 = {"tosbaamodel2", "zipzipmodel2",  "foxmodel2", "atmodel2", "devemodel2", "cheetahmodel2"}; private String[] animalReread = {"tosbaareread", "zipzipreread",  "foxreread", "atreread", "devereread", "cheetahreread"}; private String[] animalReread2 = {"tosbaareread2", "zipzipreread2",  "foxreread2", "atreread2", "devereread2", "cheetahreread2"}; private String[] animalReread3 = {"tosbaareread3", "zipzipreread3",  "foxreread3", "atreread3", "devereread3", "cheetahreread3"}; private String[] animalshutup = {"tosbaailk6", "zipzipgozuacik2",  "foxacik5", "atacik6", "deveacik4", "cheetahacik5"}; private boolean intro = false;  @Override protected void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);     setContentView(R.layout.activity_animation);     initializeVariables();  //initializing variables     if(animwhich.equals("intro")){         intro = true;         setvideo(animalIntro[(int) Math.floor(level/12.1)]);     }     else{         if(animwhich.equals("model")) {             if(strategy.equals("x"))                 setvideo(animalModel2[(int) Math.floor(level/12.1)]);             else                 setvideo(animalModel[(int) Math.floor(level/12.1)]);         }else {             if (animwhich.equals("reread")) {                 switch (Integer.parseInt(condition)){                     case 2:                         setvideo(animalReread2[(int)    Math.floor(level/12.1)]);                         break;                     case 3:                         setvideo(animalReread3[(int)   Math.floor(level/12.1)]);                         break;                     default:                         setvideo(animalReread[(int)  Math.floor(level/12.1)]);                         break;                 }             }         }     } }  private void initializeVariables() {     animwhich = configureText("animwhich", "model");     strategy = configureText("strategy", "y");     condition= configureText("condition", "1");     level = configureNumber("level");     anime =  findViewById(R.id.imageView); }  private void setvideo(final String file) {     anime.setImageDrawable(getResources().getDrawable(getResources().             getIdentifier("drawable/" + file, null,   getPackageName())));     running = (AnimationDrawable) anime.getDrawable();     running.start();     if (player == null) {         player = MediaPlayer.create(this,   getResources().getIdentifier(file, "raw", getPackageName()));         player.setOnCompletionListener(new  MediaPlayer.OnCompletionListener() {             @Override             public void onCompletion(MediaPlayer mp) {                 stopPlayer();             }         });     }     if (player != null) {         player.start();     } }  private void stopPlayer() {     if (player != null) {         player.release();         player = null;         running.stop();         final Intent getData = getIntent();           anime.setImageDrawable(getResources().getDrawable(getResources().                 getIdentifier("drawable/" + animalshutup[(int)  Math.floor(level/12.1)], null, getPackageName())));         final Handler handler = new Handler();         handler.postDelayed(new Runnable() {             @Override             public void run() {                 final Intent intent;                 if (animwhich.equals("reread")) {                     intent = new Intent(AnimationActivity.this,  Reread1Activity.class);                     }                 }             }         }, 2000);     } }  @Override protected void onStop() {     super.onStop();     stopPlayer(); }  private int configureNumber(String tag){     Intent getData = getIntent();     int value;     if(getData.getStringExtra(tag)==null)         value=1;     else     if(getData.getStringExtra(tag).matches("-?([1-      9]\\d*)")&&Integer.parseInt(getData.getStringExtra(tag))>0)         value= Integer.parseInt(getData.getStringExtra(tag));     else         value=1;     return value; }  private String configureText(String tag, String deflt){     Intent getData = getIntent();     String value;     if(getData.getStringExtra(tag)==null)         value=deflt;     else     if(getData.getStringExtra(tag).isEmpty())         value=deflt;     else         value= getData.getStringExtra(tag);     return value; } } 

My screen xml code is below:

<?xml version="1.0" encoding="utf-8"?> <FrameLayout  xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity">  <ImageView     app:srcCompat="@drawable/arkaplansabit"     android:id="@+id/backgr"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:scaleType="fitXY"     app:layout_constraintBottom_toBottomOf="parent"     app:layout_constraintEnd_toEndOf="parent"     app:layout_constraintStart_toStartOf="parent"     app:layout_constraintTop_toTopOf="parent"      />  <ImageView     android:id="@+id/imageView"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:scaleType="fitXY"     app:layout_constraintBottom_toBottomOf="parent"     app:layout_constraintEnd_toEndOf="parent"     app:layout_constraintStart_toStartOf="parent"     app:layout_constraintTop_toTopOf="parent" /> </FrameLayout> 

My animation list xml code is below:

<?xml version="1.0" encoding="utf-8"?> <animation-list   xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/zipzipgozuacik2"     android:duration="1600"/> <item android:drawable="@drawable/zipzipgozuacik1"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik2"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik3"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik4"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik5"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik6"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik1"     android:duration="100"/> <item android:drawable="@drawable/zipzipgozuacik2"     android:duration="300"/> <item android:drawable="@drawable/zipzipgozukapali1"     android:duration="100"/> <item android:drawable="@drawable/zipzipgozukapali2"     android:duration="100"/> <item android:drawable="@drawable/zipzipgozukapali3"     android:duration="100"/> <item android:drawable="@drawable/zipzipgozukapali4"     android:duration="100"/> <item android:drawable="@drawable/zipzipgozukapali5"     android:duration="100"/> <item android:drawable="@drawable/zipzipgozukapali6"     android:duration="100"/> <item android:drawable="@drawable/zipzipgozuacik1"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik2"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik3"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik4"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik5"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik2"     android:duration="300"/> <item android:drawable="@drawable/zipzipgozuacik1"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik2"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik3"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik4"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik5"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik6"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik1"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik2"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik3"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik4"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik5"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik6"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik2"     android:duration="400"/> <item android:drawable="@drawable/zipzipgozuacik1"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik2"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik3"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik4"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik5"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik6"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozukapali1"     android:duration="100"/> <item android:drawable="@drawable/zipzipgozukapali2"     android:duration="50"/> <item android:drawable="@drawable/zipzipgozukapali3"     android:duration="50"/> <item android:drawable="@drawable/zipzipgozukapali4"     android:duration="50"/> <item android:drawable="@drawable/zipzipgozukapali5"     android:duration="50"/> <item android:drawable="@drawable/zipzipgozukapali6"     android:duration="100"/> <item android:drawable="@drawable/zipzipgozuacik2"     android:duration="1100"/> <item android:drawable="@drawable/zipzipgozuacik1"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik2"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik3"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik4"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik5"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik6"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik1"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik2"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik3"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik4"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik5"     android:duration="100"/> <item android:drawable="@drawable/zipzipgozuacik2"     android:duration="500"/> <item android:drawable="@drawable/zipzipgozuacik1"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik2"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik3"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik4"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik5"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik6"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik1"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik2"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik3"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik4"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik5"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik6"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozukapali1"     android:duration="100"/> <item android:drawable="@drawable/zipzipgozukapali2"     android:duration="100"/> <item android:drawable="@drawable/zipzipgozukapali4"     android:duration="100"/> <item android:drawable="@drawable/zipzipgozukapali5"     android:duration="100"/> <item android:drawable="@drawable/zipzipgozukapali6"     android:duration="100"/> <item android:drawable="@drawable/zipzipgozuacik2"     android:duration="800"/> <item android:drawable="@drawable/zipzipgozuacik1"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik2"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik3"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik4"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik5"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik6"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik1"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik2"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik3"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik4"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik5"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik6"     android:duration="100"/> <item android:drawable="@drawable/zipzipgozuacik2"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik1"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik2"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik3"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik4"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik5"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik6"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik1"     android:duration="100"/> <item android:drawable="@drawable/zipzipgozuacik2"     android:duration="500"/> <item android:drawable="@drawable/zipzipgozuacik2"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik3"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik4"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik5"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik6"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozukapali1"     android:duration="100"/> <item android:drawable="@drawable/zipzipgozukapali2"     android:duration="100"/> <item android:drawable="@drawable/zipzipgozukapali3"     android:duration="100"/> <item android:drawable="@drawable/zipzipgozukapali4"     android:duration="100"/> <item android:drawable="@drawable/zipzipgozukapali5"     android:duration="100"/> <item android:drawable="@drawable/zipzipgozukapali6"     android:duration="100"/> <item android:drawable="@drawable/zipzipgozuacik1"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik2"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik3"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik2"     android:duration="400"/> <item android:drawable="@drawable/zipzipgozuacik1"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik2"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik3"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik4"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik5"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik6"     android:duration="200"/> <item android:drawable="@drawable/zipzipgozuacik2"     android:duration="20000"/> 

Please help me with this issue.

THANK YOU

Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.