Android 应用程序可能在主线程中做了太多的工作?

Android 应用程序可能在主线程中做了太多的工作?,android,android-intent,android-activity,Android,Android Intent,Android Activity,我一直有一个问题,我的食谱书应用程序,它说我做了太多的工作,在主线程。我已附上我的代码。有人能告诉我为什么会这样吗??我以前从未收到过,其他帖子也没用。如果有人有答案,你能详细解释一下吗??我是新来的。我需要你向我解释这件事,就像我5岁一样,尽可能地屈尊 package com.example.recipebook; import com.example.recipebook.util.SystemUiHider; import android.view.View; import andro

我一直有一个问题,我的食谱书应用程序,它说我做了太多的工作,在主线程。我已附上我的代码。有人能告诉我为什么会这样吗??我以前从未收到过,其他帖子也没用。如果有人有答案,你能详细解释一下吗??我是新来的。我需要你向我解释这件事,就像我5岁一样,尽可能地屈尊

package com.example.recipebook;

import com.example.recipebook.util.SystemUiHider;

import android.view.View;
import android.widget.Button;
import android.app.Activity;
import android.os.Bundle;
import android.content.Intent;

public class MainPage extends Activity{
    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_page);
        Button searchButton = (Button) findViewById(R.id.triggerSearch);
        Button submitButton = (Button) findViewById(R.id.triggerSubmit);
        searchButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                openSearchPage();
            }
        });
        submitButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                openSubmitPage();
            }
        });
    }

public void openSearchPage(){
    Intent openSearchPage = new Intent(this,SearchPage.class);
    startActivity(openSearchPage);
}

public void openSubmitPage(){
    Intent openSubmitPage = new Intent(this,SumbitRecipePage.class);
    startActivity(openSubmitPage);
 }
}

package com.example.recipebook;

import android.app.Activity;
import android.os.Bundle;

public class SumbitRecipePage extends Activity{
    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.submitrecipepage);
    }
}


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#ffd100">

<Button
    android:layout_weight="1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Search"
    android:id="@+id/triggerSearch"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignRight="@+id/triggerSubmit"
    android:layout_alignEnd="@+id/triggerSubmit" />

<Button
    android:layout_weight="1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Submit"
    android:id="@+id/triggerSubmit"
    android:layout_below="@+id/triggerSearch"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignRight="@+id/button3"
    android:layout_alignEnd="@+id/button3" />

<Button
    android:layout_weight="1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Categories"
    android:id="@+id/button3"
    android:layout_below="@+id/triggerSubmit"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignRight="@+id/button4"
    android:layout_alignEnd="@+id/button4" />

<Button
    android:layout_weight="1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Favourites"
    android:id="@+id/button4"
    android:layout_below="@+id/button3"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignRight="@+id/button5"
    android:layout_alignEnd="@+id/button5" />

<Button
    android:layout_weight="1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Shopping List"
    android:id="@+id/button5"
    android:layout_below="@+id/button4"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignRight="@+id/button6"
    android:layout_alignEnd="@+id/button6" />

<Button
    android:layout_weight="1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Pantry"
    android:id="@+id/button6"
    android:layout_below="@+id/button5"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignRight="@+id/button7"
    android:layout_alignEnd="@+id/button7" />

<Button
    android:layout_weight="10"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Random Recipe"
    android:id="@+id/button7"
    android:layout_below="@+id/button6"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />

</RelativeLayout>


<?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="match_parent">

</LinearLayout>

<?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="match_parent">

</LinearLayout>

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.recipebook" >

  <application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.recipebook.MainPage"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:label="@string/app_name"
        android:theme="@style/FullscreenTheme" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>

这是因为android的编舞没有获得执行正确显示所需的资源,因此跳过了帧

这主要发生在用户在主线程中执行繁重的操作时,记住Android是单线程系统,有一个主线程,所有其他子系统都在该线程上执行任务,例如活动、服务、内容提供者。这就是为什么当您直接在主服务器上执行网络操作时,会收到应用程序未响应的消息

要详细说明您的情况,请执行以下操作

若你们有任何网络操作是在主线程中完成的,那个么将它们移动到一个单独的线程中,在Android native中我们有AsyncTask,尝试在Phonegap中查找线程机制

如果您有任何繁重的操作,如位图压缩等,请通过线程或后期可运行逻辑有效地处理它们,这将确保您的主线程可以自由执行琐碎的任务,如生成事件的显示处理等

从这个意义上说,任何可能需要一些时间的逻辑,将其移动到线程,这将确保您的显示运行平稳


希望能有所帮助。

您发布的任何代码都不应导致此问题。您在何处/何时看到此错误?03-09 14:34:51.909 372-387/system_process I/Choreographer﹕ 跳过98帧!应用程序可能在其主线程上做了太多工作。03-09 14:34:56.629 528-528/com.android.launcher I/编舞﹕ 跳过47帧!应用程序可能在其主线程上做了太多工作。如果你的应用程序退出,你应该在logcat中看到stacktrace。你没发那个。如果您没有看到,请检查您是否没有安装logcat,因为您可能会错过一些重要的内容。此外,如果您在单击启动另一个活动的按钮时遇到这些错误,则应检查该活动是否已实际启动(在activty中添加日志记录),并在
onCreate()
中检查您可能正在执行的操作,
onStart()
onResume()
,所有这些都将在您启动另一个活动时调用。
03-09 14:37:00.329    1145-1145/com.example.recipebook I/Choreographer﹕ Skipped 38 frames!  The application may be doing too much work on its main thread.
03-09 14:37:02.909      372-387/system_process I/Choreographer﹕ Skipped 68 frames!  The application may be doing too much work on its main thread.
03-09 14:37:03.299      372-386/system_process I/Choreographer﹕ Skipped 31 frames!  The application may be doing too much work on its main thread.
03-09 14:37:03.509      372-386/system_process I/Choreographer﹕ Skipped 42 frames!  The application may be doing too much work on its main thread.
03-09 14:37:03.719      372-386/system_process I/Choreographer﹕ Skipped 31 frames!  The application may be doing too much work on its main thread.
03-09 14:37:03.789      372-387/system_process I/Choreographer﹕ Skipped 116 frames!  The application may be doing too much work on its main thread.
03-09 14:37:03.999      372-386/system_process I/Choreographer﹕ Skipped 30 frames!  The application may be doing too much work on its main thread.
03-09 14:37:04.209      372-386/system_process I/Choreographer﹕ Skipped 41 frames!  The application may be doing too much work on its main thread.
03-09 14:37:04.429      372-387/system_process I/Choreographer﹕ Skipped 42 frames!  The application may be doing too much work on its main thread.
03-09 14:37:04.909      372-387/system_process I/Choreographer﹕ Skipped 63 frames!  The application may be doing too much work on its main thread.
03-09 14:37:04.929      528-528/com.android.launcher I/Choreographer﹕ Skipped 297 frames!  The application may be doing too much work on its main thread.
03-09 14:37:06.199      372-386/system_process I/Choreographer﹕ Skipped 30 frames!  The application may be doing too much work on its main thread.
03-09 14:37:06.909      372-386/system_process I/Choreographer﹕ Skipped 33 frames!  The application may be doing too much work on its main thread.
03-09 14:37:07.299      372-386/system_process I/Choreographer﹕ Skipped 98 frames!  The application may be doing too much work on its main thread.
03-09 14:37:07.529      372-386/system_process I/Choreographer﹕ Skipped 37 frames!  The application may be doing too much work on its main thread.
03-09 14:37:07.849      372-386/system_process I/Choreographer﹕ Skipped 61 frames!  The application may be doing too much work on its main thread.
03-09 14:37:08.039      372-386/system_process I/Choreographer﹕ Skipped 47 frames!  The application may be doing too much work on its main thread.
03-09 14:37:09.789      372-387/system_process I/Choreographer﹕ Skipped 77 frames!  The application may be doing too much work on its main thread.