Android TextView using setText(string) every second - Perfomance issue (up to 16.6 ms)

Viewed 21
  1. No layout hierarchy problem (just a single TextView)
  2. No measure problem (TextView has fixed size)
  3. In this example a single char per second
  4. Release version of project (No debug for test perfomance)

How can i draw text on UI below 16 ms? If this is TextView issue , there is another way to draw text below 16 ms?

Code from main activity :

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        TextView test = findViewById(R.id.test);

        Handler h = new Handler();
        Random r = new Random();

        h.post(new Runnable() {
            @Override
            public void run() {
                test.setText(String.valueOf(r.nextInt(9)));
                h.postDelayed(this, 1000);
            }
        });
    }
}

Code from activity_main.xml :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/parent"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:orientation="vertical">

    <TextView
        android:id="@+id/test"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:text="Hello World!" />

</LinearLayout>

Rendering Perfomance When Device is not connected with Android Studio: Gpu Rendering Image

Rendering Perfomance When Device is connected with Android Studio: Gpu Rendering Image

Bad perfomance is cpu-gpu issue(maybe cause of idle mode)? if yes, how can i solve it?

0 Answers
Related