Hello! I can not overcome the error. After several updates of the fragment (4 elements are updated immediately), it hangs up and then gives the following message:

Skipped 2137 frames! The application may be doing too much work on its main thread and after that the fragment resets all UI settings.

Java code

if (RootTools.isBusyboxAvailable()) { if (RootTools.isRootAvailable()) { if (RootTools.isAccessGiven()) { Command command1 = new Command(0, "pgrep rngd") { @Override public void commandOutput(int id, String line) { super.commandOutput(id, line); if (line.matches("[0-9]+")) { entropystatus = (TextView) getActivity().findViewById(R.id.entropystatus); entropystatus.setText("СТАТУС СЕРВИСА: ВКЛЮЧЕН"); entropystatus.setBackgroundResource(R.drawable.roundbuttongood); startentropy = (Button) getActivity().findViewById(R.id.startentropy); startentropy.setBackgroundResource(R.drawable.roundbuttonfuck); startentropy.setEnabled(false); startentropy.setTextColor(Color.WHITE); stopentropy = (Button) getActivity().findViewById(R.id.stopentropy); stopentropy.setBackgroundResource(R.drawable.roundbuttoncal); stopentropy.setEnabled(true); stopentropy.setTextColor(Color.WHITE); stopentropy.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (RootTools.isBusyboxAvailable()) { if (RootTools.isRootAvailable()) { if (RootTools.isAccessGiven()) { Command command1 = new Command(0, "entropy_disable"); try { Toast.makeText(getActivity(), "Сервис остановлен!", Toast.LENGTH_SHORT).show(); RootTools.getShell(true).add(command1); } catch (IOException | RootDeniedException | TimeoutException ex) { ex.printStackTrace(); Toast.makeText(getActivity(), "ОШИБКА. СВЯЖИТЕСЬ С РАЗРАБОТЧИКОМ", Toast.LENGTH_SHORT).show(); } } else { Toast.makeText(getActivity(), "ОШИБКА! ", Toast.LENGTH_SHORT).show(); } } else { Toast.makeText(getActivity(), "ОШИБКА!", Toast.LENGTH_SHORT).show(); } } else { Toast.makeText(getActivity(), "ОШИБКА! НЕ УСТАНОВЛЕН BUSYBOX!", Toast.LENGTH_SHORT).show(); RootTools.offerBusyBox(getActivity()); } } }); } } @Override public void commandCompleted(int id, int exitcode) { super.commandCompleted(id, exitcode); if (exitcode==1) { entropystatus = (TextView) getActivity().findViewById(R.id.entropystatus); entropystatus.setText("СТАТУС СЕРВИСА: ВЫКЛЮЧЕН"); entropystatus.setBackgroundResource(R.drawable.roundbuttonbad); stopentropy = (Button) getActivity().findViewById(R.id.stopentropy); stopentropy.setBackgroundResource(R.drawable.roundbuttonfuck); stopentropy.setEnabled(false); stopentropy.setTextColor(Color.WHITE); startentropy = (Button) getActivity().findViewById(R.id.startentropy); startentropy.setBackgroundResource(R.drawable.roundbuttoncal); startentropy.setEnabled(true); startentropy.setTextColor(Color.WHITE); startentropy.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v){ if (RootTools.isBusyboxAvailable()) { if (RootTools.isRootAvailable()) { if (RootTools.isAccessGiven()) { Command command1 = new Command(0, "entropy_enabler"); try { Toast.makeText(getActivity(), "Сервис запущен!", Toast.LENGTH_SHORT).show(); RootTools.getShell(true).add(command1); } catch (IOException | RootDeniedException | TimeoutException ex) { ex.printStackTrace(); Toast.makeText(getActivity(), "ОШИБКА. СВЯЖИТЕСЬ С РАЗРАБОТЧИКОМ", Toast.LENGTH_SHORT).show(); } } else { Toast.makeText(getActivity(), "ОШИБКА! ", Toast.LENGTH_SHORT).show(); } } else { Toast.makeText(getActivity(), "ОШИБКА!", Toast.LENGTH_SHORT).show(); } } else { Toast.makeText(getActivity(), "ОШИБКА! НЕ УСТАНОВЛЕН BUSYBOX!", Toast.LENGTH_SHORT).show(); RootTools.offerBusyBox(getActivity()); } } }); } } }; try { RootTools.getShell(true).add(command1); } catch (IOException | RootDeniedException | TimeoutException ex) { ex.printStackTrace(); } } else { } } else { } } else { RootTools.offerBusyBox(getActivity()); } 

Layout code

 <?xml version="1.0" encoding="utf-8"?> 

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content" android:weightSum="1"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="" android:id="@+id/entropystatus" android:layout_weight="0.04" android:gravity="center_vertical|center|center_horizontal" android:textColor="#ffffff" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="Entropy Generator позволяет ускорить работу устройства путем выполнения специальных операций в /dev/random. Учтите, что данная утилита действительно полезна только для старых версий Android (ниже 4.4), на Android 4.4-6.0 она, естественно, работает, но существенного эффекта прироста производительности Вы скорее всего не заметите" android:id="@+id/textView33" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="Сначала, если требуется, установите библиотеку по работе с Entropy, потом чтобы включить Entropy Generator, нажмите соответствующую кнопку\n\n" android:id="@+id/textView35" /> <Button android:layout_width="330dp" android:layout_height="55dp" android:text="Установить библиотеку работы с Entropy Generator\n" android:id="@+id/entropy" android:layout_gravity="top|center_horizontal" android:layout_marginBottom="10dp" android:gravity="center_vertical|center|center_horizontal" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceSmall" android:text="Статус кнопки обновляется только после перезагрузки страницы" android:id="@+id/textView9" android:layout_gravity="center_horizontal" android:layout_marginTop="-10dp" android:layout_marginBottom="10dp" android:gravity="center_vertical|center|center_horizontal" android:textSize="10dp" /> <FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="0.03"> <Button android:layout_width="162dp" android:layout_height="wrap_content" android:text="Запустить сервис" android:id="@+id/startentropy" android:layout_weight="0.04" android:layout_gravity="left|top" /> <Button android:layout_width="159dp" android:layout_height="wrap_content" android:text="Остановить сервис" android:id="@+id/stopentropy" android:layout_weight="0.04" android:layout_gravity="right|top" /> </FrameLayout> <Button android:layout_width="322dp" android:layout_height="wrap_content" android:text="Удалить Entropy Generator из системы" android:id="@+id/delete" android:layout_gravity="center_horizontal" android:layout_weight="0.04" android:layout_marginTop="10dp" /> </LinearLayout> 

Tried to hang UI changes of each element on:

  getActivity().runOnUiThread(new Runnable() { @Override public void run() { } }); 

Does not help.

  • 2
    I think the message on the contrary says that there is too much work in the main thread, but everyone usually ignores it. - pavel
  • I also tried to redistribute work via runOnUiThread, it does not help ( - NowenUI
  • Well, I recently started doing this kind of development, I don’t really know it with streams, so excuse me if I do something a little wrong) - NowenUI
  • one
    Let's say this from the main thread you can not cause anything outside the network (this android itself will not give) and generally do not load it except for user interaction. Of course there are exceptions but rarely. - pavel

1 answer 1

Take out all the hard work in AsyncTask tyts tyts and tyts

However, asynctasks have recently been used less and less, due to the fact that the result will go into "remote" activation, for example, if the user rotates the screen during operation and for many other reasons

Because I recommend to pay attention to Chronos There is a detailed wiki on the use of libraries here.

  • Thank! And what about Handler or runOnUiThread? Simply, they are more attractive, no need to create additional classes, to describe in several methods, such as in AsyncTask and in Chronos - NowenUI
  • one
    The runOnUiThread method, as the name implies, is generally not suitable for you, since it executes the Ui code of the Handler stream and only allows you to control the event chain and, by default, also works with the Ui stream. To execute code in a new thread, look towards Runnable, if you don’t need to transfer the result to IU or asynctask after work, if necessary. But I would recommend using Chronos. - Roman Novoselov
  • Didn't see even nicer site: D - dirkgntly
  • I would also advise IntentService every task is performed in a new stream, the results can be returned via BroadcastReceiver - Kirill Stoianov