In my Android vitals 30% of my users experience slow rendering. My app has a pretty complicated UI so I made a really basic project to try to solve this problem. But it turns out it's pretty slow even with the simplest of layouts.
The layout is a centered text that Android studio offers as a template:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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="slowrenderingtest.pichaipls.com.slowrenderingtest.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/timerView"
android:text="00:00"
android:textSize="40dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</android.support.constraint.ConstraintLayout>
The activity that uses the layout changes the text every second (because it's a timer):
Timer updateTicks = new Timer();
updateTicks.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
Random r = new Random();
timerView.setText(String.format("%02d", r.nextInt(60))+":"+
String.format("%02d", r.nextInt(60)));
}
});
}
}, 100, 1000);
When I turn on GPU profiling, this is getting pretty close to the 16ms limit for drawing each frame on some slower devices (apparently 30% of my users). Just one TextView. But here's the catch: when I first run the activity the rendering times are low but then they shoot up after a few seconds. If I keep touching the screen (there are no controls on the screen), the rendering times remain low. I'm guessing this is due to the CPU/GPU going to a low power state (so rendering takes longer).
My problem is the Android vitals. I keep seeing the warning about slow rendering times (I think anything above 5% of sessions experiencing slow rendering gets a warning) but I don't know how I can speed this up. And I'm worried it may affect my app's ranking but even with this really simple example far too many Android users have slow devices.
Can anything be done about this?