当我打开一个带有按钮的新屏幕时,我的应用程序将不会响应并显示ANR, 因为我的应用程序花了很长时间来加载页面,但我不知道如何解决我的问题。
它可以在较旧的Android设备上运行,但在我的设备上该应用程序已被停止:'(
如果您需要更多信息,请询问;)
我在最新版本的Android 4.1.1上运行了一个HTC one X. 我有一个你可以听的应用程序并免费下载音乐,我对1个布局有很多看法,超过80个视图都是问题。
我可以给你代码,但我的所有代码都工作,因为在Android 3.3.7一切正常在三星galaxy迷你。问题是我想让我的应用程序有更多时间打开新屏幕,因为我已经读过5秒后自动弹出ANR
的 logcat的: 的
04-17 22:26:48.333: I/dalvikvm(20428): at dalvik.system.NativeStart.main(Native Method)
04-17 22:26:48.333: E/dalvikvm(20428): Out of memory: Heap Size=65571KB, Allocated=62502KB, Limit=65536KB
04-17 22:26:48.333: E/dalvikvm(20428): Extra info: Footprint=63651KB, Allowed Footprint=65571KB, Trimmed=0KB
04-17 22:26:48.333: D/skia(20428): --- decoder->decode returned false
04-17 22:26:48.333: W/dalvikvm(20428): threadid=1: thread exiting with uncaught exception (group=0x41b4e2d0)
04-17 22:26:48.348: E/AndroidRuntime(20428): FATAL EXCEPTION: main
04-17 22:26:48.348: E/AndroidRuntime(20428): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.listentomusic/com.example.listentomusic.March}: android.view.InflateException: Binary XML file line #1209: Error inflating class <unknown>
04-17 22:26:48.348: E/AndroidRuntime(20428): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2351)
04-17 22:26:48.348: E/AndroidRuntime(20428): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
04-17 22:26:48.348: E/AndroidRuntime(20428): at android.app.ActivityThread.access$600(ActivityThread.java:151)
04-17 22:26:48.348: E/AndroidRuntime(20428): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1331)
04-17 22:26:48.348: E/AndroidRuntime(20428): at android.os.Handler.dispatchMessage(Handler.java:99)
04-17 22:26:48.348: E/AndroidRuntime(20428): at android.os.Looper.loop(Looper.java:155)
04-17 22:26:48.348: E/AndroidRuntime(20428): at android.app.ActivityThread.main(ActivityThread.java:5485)
04-17 22:26:48.348: E/AndroidRuntime(20428): at java.lang.reflect.Method.invokeNative(Native Method)
04-17 22:26:48.348: E/AndroidRuntime(20428): at java.lang.reflect.Method.invoke(Method.java:511)
04-17 22:26:48.348: E/AndroidRuntime(20428): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
04-17 22:26:48.348: E/AndroidRuntime(20428): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:795)
04-17 22:26:48.348: E/AndroidRuntime(20428): at dalvik.system.NativeStart.main(Native Method)
04-17 22:26:48.348: E/AndroidRuntime(20428): Caused by: android.view.InflateException: Binary XML file line #1209: Error inflating class <unknown>
04-17 22:26:48.348: E/AndroidRuntime(20428): at android.view.LayoutInflater.createView(LayoutInflater.java:613)
04-17 22:26:48.348: E/AndroidRuntime(20428): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
04-17 22:26:48.348: E/AndroidRuntime(20428): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
04-17 22:26:48.348: E/AndroidRuntime(20428): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
04-17 22:26:48.348: E/AndroidRuntime(20428): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
04-17 22:26:48.348: E/AndroidRuntime(20428): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
04-17 22:26:48.348: E/AndroidRuntime(20428): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
04-17 22:26:48.348: E/AndroidRuntime(20428): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
04-17 22:26:48.348: E/AndroidRuntime(20428): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
04-17 22:26:48.348: E/AndroidRuntime(20428): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
04-17 22:26:48.348: E/AndroidRuntime(20428): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:365)
04-17 22:26:48.348: E/AndroidRuntime(20428): at android.app.Activity.setContentView(Activity.java:1912)
04-17 22:26:48.348: E/AndroidRuntime(20428): at com.example.listentomusic.March.onCreate(March.java:15)
04-17 22:26:48.348: E/AndroidRuntime(20428): at android.app.Activity.performCreate(Activity.java:5066)
04-17 22:26:48.348: E/AndroidRuntime(20428): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1101)
04-17 22:26:48.348: E/AndroidRuntime(20428): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307)
04-17 22:26:48.348: E/AndroidRuntime(20428): ... 11 more
04-17 22:26:48.348: E/AndroidRuntime(20428): Caused by: java.lang.reflect.InvocationTargetException
04-17 22:26:48.348: E/AndroidRuntime(20428): at java.lang.reflect.Constructor.constructNative(Native Method)
04-17 22:26:48.348: E/AndroidRuntime(20428): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
04-17 22:26:48.348: E/AndroidRuntime(20428): at android.view.LayoutInflater.createView(LayoutInflater.java:587)
04-17 22:26:48.348: E/AndroidRuntime(20428): ... 26 more
04-17 22:26:48.348: E/AndroidRuntime(20428): Caused by: java.lang.OutOfMemoryError: (Heap Size=65571KB, Allocated=62502KB)
04-17 22:26:48.348: E/AndroidRuntime(20428): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
04-17 22:26:48.348: E/AndroidRuntime(20428): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:626)
04-17 22:26:48.348: E/AndroidRuntime(20428): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:473)
04-17 22:26:48.348: E/AndroidRuntime(20428): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:781)
04-17 22:26:48.348: E/AndroidRuntime(20428): at android.content.res.Resources.loadDrawable(Resources.java:1959)
04-17 22:26:48.348: E/AndroidRuntime(20428): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
04-17 22:26:48.348: E/AndroidRuntime(20428): at android.widget.ImageView.<init>(ImageView.java:120)
04-17 22:26:48.348: E/AndroidRuntime(20428): at android.widget.ImageView.<init>(ImageView.java:110)
04-17 22:26:48.348: E/AndroidRuntime(20428): ... 29 more
xml文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/standaard_background" >
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/maart"
android:textSize="30sp"
android:textColor="#FFFFFF"
android:background="#000000" />
<android.support.v7.widget.Space
android:id="@+id/space1"
android:layout_width="fill_parent"
android:layout_height="15dp" />
<ListView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<!-- start -->
<!-- song1 -->
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/s1"
android:background="#FFFFFF"/>
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="137dp"
android:contentDescription="@string/imageView1"
android:src="@drawable/a" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:text="@string/play"
android:id="@+id/btnsong1_1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
</Button>
<Button
android:text="@string/download"
android:id="@+id/btnsong1_2"
android:layout_toRightOf="@id/btnsong1_1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
</Button>
</LinearLayout>
...
<!-- song40 -->
<TextView
android:id="@+id/textView41"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/s40"
android:background="#FFFFFF"/>
<ImageView
android:id="@+id/imageView40"
android:layout_width="match_parent"
android:layout_height="137dp"
android:contentDescription="@string/imageView1"
android:src="@drawable/zn" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:text="@string/play"
android:id="@+id/btnsong40_1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
</Button>
<Button
android:text="@string/download"
android:id="@+id/btnsong40_2"
android:layout_toRightOf="@id/btnsong40_1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
</Button>
</LinearLayout>
<!-- end -->
</LinearLayout>
</ListView>
</LinearLayout>
的.java:
package com.example.listentomusic;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Menu extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
Button btnmarch = (Button) findViewById(R.id.btnmarch);
btnmarch.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated catch block
startActivity(new Intent("android.intent.action.MARCH"));
}
});
}
}
android manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.listentomusic"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="16" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.listentomusic.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Menu"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".About"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.ABOUT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".March"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
答案 0 :(得分:0)
内存不足:
这是您需要解决的问题。
我对1个布局有很多观点超过80个观点就是这样 问题
尝试减少视图的数量并运行我认为它将运行的问题是您在布局中创建的大量视图。这将因设备而异,某些设备可能支持您拥有的大量视图。
我最近遇到了类似的问题,布局在大多数主要设备(三星,摩托罗拉,LG)上工作正常但在索尼Xperia S上崩溃。