【问题标题】:Choreogrpher Issues编舞问题
【发布时间】:2018-04-28 20:50:36
【问题描述】:

我的应用有问题。它给了我警告:我/编舞:跳过了 43 帧!应用程序可能在其主线程上做了太多工作。

我的应用程序有 2 个非常简单的活动,实际上其中之一我不编写它的代码。其中一个是带有进度条的启动画面,另一个只显示一些元素。

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>

只有这个代码我已经遇到了Choreographer的问题,我不知道为什么,因为它只有一个操作,那就是升级progressBar。

我的可绘制文件夹有这个:

  • action_button_shape.xml (v24)
  • app_background.webp
  • boton_measurement.webp (v24)
  • boton_measurement_pressed.webp (v24)
  • custom_progressbar.xml (v24)
  • custom_progressbar_horizo​​ntal.xml
  • img_loader.webp

我不知道drawable和drawable-24的区别。

我做了几个测试:

  • 在 android studio 模拟器中完美运行(nexus_5x API 24)
  • 在我的手机里给我编舞问题,有无drawable-24元素(小米米max API 24)
  • 在另一部手机我不能使用drawable-24,但改成drawable,它工作正常(小米红米3s API 23)

我的手机会发生什么?

【问题讨论】:

    标签: java android


    【解决方案1】:

    正如这里提到的The application may be doing too much work on its main thread。您还应该检查可绘制对象的大小。

    现在尝试缩小图像大小 (@drawable/app_background @drawable/img_loadpage) 或将它们移动到 drawable-xxxhdpi

    【讨论】:

    • 它们的大小分别为 7,1KB 和 37,1KB。是不是太多了?
    • @SergioGarcia 不是真的,但我会尝试我的建议以确保
    • 它似乎有效,这种将所有图像移动到drawable-xxxhdpi的解决方案是一个好习惯吗?无论如何,我必须在整个应用程序中探测它,因为这只是为了“调试”另一个 jaja
    • @SergioGarcia 在旧设备上可能会出现问题...但是如果您使用此Android studio plugin 导入 png 图像,它应该 super 没问题。 (如果工作量太大,请尝试忽略较小的)我还建议将 vectorDrawable 用于图标。
    • 非常感谢,因为问题是这样的。我在整个应用程序上对其进行了探索,并且知道效果很好。多么烦人的事情,只移动超过 1KB 的图像。不是旧设备的问题,因为我的设备只有 1 年,而我探测它的另一台设备比我的最差和旧,所以我不知道但知道工作。谢谢……
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-08
    • 2021-05-22
    • 1970-01-01
    • 2023-04-01
    • 1970-01-01
    • 2014-06-15
    • 2012-04-22
    相关资源
    最近更新 更多