gpt4 book ai didi

java - 应用程序可能在新项目上的主线程错误上做了太多工作

转载 作者:太空宇宙 更新时间:2023-11-04 11:53:54 25 4
gpt4 key购买 nike

基本上我正在尝试学习java和android应用程序开发。最近,我创建了一个新项目,并设计了一个简单的布局,其中有一个按钮,并加载了主要 Activity 。

现在我遇到了以下错误,甚至没有实现按钮功能和东西等。它只是加载和显示布局,但花费了太多时间。例如:当我在模拟器或我的个人设备上加载它时......加载大约需要 10 秒,然后当我单击按钮时应用程序会跳过帧......

01/08 09:19:48: Launching app
No apk changes detected since last installation, skipping installation of C:\Users\nouma\AndroidStudioProjects\MediEase\app\build\outputs\apk\app-debug.apk
$ adb shell am force-stop com.example.nouma.mediease
$ adb shell am start -n "com.example.nouma.mediease/com.example.nouma.mediease.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Connected to process 3520 on device Nexus_5X_API_23 [emulator-5554]
W/System: ClassLoader referenced unknown path: /data/app/com.example.nouma.mediease-2/lib/x86
D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true

[ 01-08 09:19:49.686 3520: 3520 D/ ]
HostConnection::get() New Host Connection established 0xaab6ddc0, tid 3520


[ 01-08 09:19:49.746 3520: 3534 D/ ]
HostConnection::get() New Host Connection established 0xaff0d4e0, tid 3534
I/OpenGLRenderer: Initialized EGL, version 1.4
W/EGL_emulation: eglSurfaceAttrib not implemented
W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xaa392b60, error=EGL_SUCCESS
I/Choreographer: Skipped 213 frames! The application may be doing too much work on its main thread.
I/Choreographer: Skipped 91 frames! The application may be doing too much work on its main thread.
I/Choreographer: Skipped 75 frames! The application may be doing too much work on its main thread.
I/Choreographer: Skipped 73 frames! The application may be doing too much work on its main thread.
I/Choreographer: Skipped 67 frames! The application may be doing too much work on its main thread.
I/Choreographer: Skipped 77 frames! The application may be doing too much work on its main thread.
I/Choreographer: Skipped 89 frames! The application may be doing too much work on its main thread.

代码

package com.example.nouma.mediease;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Intent;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

//private Button mainbutton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

/* mainbutton = (Button)findViewById(R.id.begin_button);

mainbutton.setOnClickListener(
new Button.OnClickListener(){
public void onClick(View v){
startMain();
}
}
);*/
}

/*
*public void onClick(View v) {
new Thread(new Runnable() {
public void run() {
Bitmap b = loadImageFromNetwork();
mImageView.setImageBitmap(b);
}
}).start();
}
* */
void startMain(){
Intent i = new Intent(this, introActivity.class);
startActivity(i);
finish();
}
}

XML 文件:http://pastebin.com/cQ6fSmvg

最佳答案

既然没有这样的代码,错误应该来自于xml。在您的 XML 中,最有可能引发此错误的情况是您的背景图像

可能发生的情况是操作系统正在尝试对您的图像进行大量处理,您可能选择了高分辨率。您可以做的是尝试创建图像的多种分辨率(mdpi、hdpi、xhdpi、xxhdpi)。 android supporting multiple resolution with multiple layout folder

可以将图像的标准尺寸作为mdpi,将其尺寸分别按1.5、2、3的比例增大为hdpi、xhdpi、xxhdpi。当你有这些图像时,将它们放入可绘制文件夹中,如果没有,请自行创建它们。有时这甚至可能导致 android 中的 OOM。一篇文章explaining

首先尝试在 list 中添加以下行,看看是否有帮助

 <application android:largeHeap="true"

如果它没有帮助,并且您只有一张图像可在所有设备中使用,您需要将内容本身解码为可以使用此 https://stackoverflow.com/a/823966/5188159因此,如果您决定缩小规模,则需要以编程方式设置背景,而不是使用 xml

Bitmap myBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.amanda); // Replace your image name with my one
BitmapDrawable bitmapDrawable = new BitmapDrawable(MainActivity.this.getResources(), myBitmap);
relativeLayout.setBackground(bitmapDrawable); // Replace your activity with my main

关于java - 应用程序可能在新项目上的主线程错误上做了太多工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41529495/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com