I have problems with my app. It gives me the warning: I/Choreographer: Skipped 43 frames! The application may be doing too much work on its main thread.
My app has 2 very simple activities in fact one of them I do not write its code. 1 of them is a splash screen with a progressBar and the other only show some elements.
SplashScreen.java
public class SplashScreen extends AppCompatActivity {
//Variables declaration
private ProgressBar progressBar;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_screen);
//Fill in variables
TextView textView = findViewById(R.id.text_splash);
progressBar = findViewById(R.id.splash_screen_progress_bar);
//Change the textView font
Typeface face = Typeface.createFromAsset(getAssets(),"fonts/ExpletusSans-BoldItalic.ttf");
textView.setTypeface(face);
//Call to the background execution
new UpdateProgressBar().execute();
}
/* Auxiliary class to operate in background:
* First parameter: in data type of function doInBackground()
* Second parameter: data type of function onProgressUpdate()
* Third parameter: out data type of function doInBackground()
* */
public class UpdateProgressBar extends AsyncTask<Void, Integer, Void> {
//Execution in background (in a different thread)
@Override
protected Void doInBackground(Void... params) {
//I want to show splashScreen for 4 seconds
for(int i = 1; i <= 4 ; i++){
oneSecond();
publishProgress(i*25);
if(isCancelled()){
break;
}
}
return null;
}
//It executes in the main thread, when I call publishProgress() in doInBackground().
@Override
protected void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values);
progressBar.setProgress(values[0]);
}
//Execute after doInBackground() in the main thread.
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
Intent change_screen = new Intent(SplashScreen.this, MeasureScreenActivity.class);
startActivity(change_screen);
//Effect of transition
overridePendingTransition(R.anim.fade_in,R.anim.fade_out);
finish();
}
}
//Auxiliary method to simulate one second
public void oneSecond(){
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
splash_screen.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/app_background">
<TextView
android:id="@+id/text_splash"
android:layout_width="match_parent"
android:layout_height="60sp"
android:layout_alignParentStart="true"
android:gravity="center"
android:layout_marginTop="35dp"
android:text="Breath Frequecy"
android:textColor="#fff"
android:textSize="30sp" />
<ImageView
android:id="@+id/splash_screen_image"
android:layout_width="match_parent"
android:layout_height="300sp"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:src="@drawable/img_loadpage" />
<ProgressBar
android:id="@+id/splash_screen_progress_bar"
android:layout_centerHorizontal="true"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="350dp"
android:layout_height="25dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="50dp"
android:progressDrawable="@drawable/custom_progressbar_horizontal"/>
</RelativeLayout>
MeasureScreenActivity.java
public class MeasureScreenActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.measure_screen);
}
}
measure_screen.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.appsgarci.prueba.MeasureScreenActivity"
android:orientation="vertical"
android:background="@drawable/app_background">
<TextView
android:id="@+id/text_measure"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="10dp"
android:paddingEnd="10dp"
android:paddingStart="10dp"
android:text="Elija la actividad que ha realizado:"
android:textAlignment="center"
android:textColor="#fff"
android:textSize="25sp" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="350dp"
android:layout_height="50dp"
android:layout_alignStart="@+id/spinner_measure"
android:layout_alignBottom="@+id/spinner_measure"
android:background="@drawable/stroke_spinner_selected"
android:id="@+id/linearLayout"
android:visibility="visible"/>
<Spinner
android:id="@+id/spinner_measure"
android:layout_width="350dp"
android:layout_height="50dp"
android:layout_below="@+id/text_measure"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp" />
<Button
android:id="@+id/button_measure"
android:layout_width="140sp"
android:layout_height="140sp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:layout_marginBottom="50dp"
android:background="@drawable/action_button_shape"
android:text="Iniciar"
android:textStyle="bold"
android:textSize="20dp"
android:visibility="visible"/>
</RelativeLayout>
Only with this code I already have the problem with Choreographer and I do not know why, because it only has one operation, that is upgrade the progressBar.
My drawable folder has this:
- action_button_shape.xml (v24)
- app_background.webp
- boton_measurement.webp (v24)
- boton_measurement_pressed.webp (v24)
- custom_progressbar.xml (v24)
- custom_progressbar_horizontal.xml
- img_loader.webp
I do not know the difference between drawable and drawable-24.
I have done several tests:
- In android studio emulator works perfectly (nexus_5x API 24)
- In my mobile phone gives me choreographer issue with and without drawable-24 elements(xiaomi mi max API 24)
- In another mobile phone I can't use drawable-24 but changing to drawable, it works fine (xiaomi redmi 3s API 23)
What could be happening in my mobile?