gpt4 book ai didi

android - 为什么我的带有 TabGroup 的 Titanium Android 应用程序存在内存和性能问题?

转载 作者:行者123 更新时间:2023-11-29 17:22:50 24 4
gpt4 key购买 nike

我在 Titanium 中有一个 iOS 应用程序,现在我想创建 Android 版本。

我的问题是在 Android 中我有很多内存问题和性能问题。

该应用程序包含一个包含三个选项卡的选项卡组。在每个选项卡中都有按钮(以及图像和信息),可让您转到另一个子窗口。我什至可以是 3 或 4 级子窗口。它还具有四个包含大量数据的数据库。

在 iOS 上,我使用:self.containingTab.open(new AddWindow); 每次我想转到另一个级别时,它允许您向后导航到上一个窗口。在 Android 上,当按下硬件后退按钮时,我也可以返回到上一个窗口,但我有很多内存不足错误。

会不会是我打开了新窗口,旧窗口还在耗内存?管理具有多个选项卡的选项卡组以及每个选项卡允许您转到不同子窗口的最佳方式是什么?

我试过创建一个 View 并添加到旧窗口而不是创建一个窗口,但是我无法返回到上一个 View ,尽管我自己管理它。

有更好的方法吗?

非常感谢!

更新

这是我收到的错误:

首先我有一些:

Unable to load bitmap. Not enough memory: Failed to allocate a
10731532 byte allocation with 9611988 free bytes and 9MB until OOM

然后,一些:

Throwing OutOfMemoryError "Failed to allocate a 10731532 byte
allocation with 5437592 free bytes and 5MB until OOM"

但应用程序仍然有效。

直到我收到:

03-16 13:56:19.951: E/art(18624): Throwing OutOfMemoryError "Failed to allocate a 344 byte allocation with 300 free bytes and 300B until OOM" (recursive case)
03-16 13:56:19.983: E/art(18624): "main" prio=5 tid=1 Runnable
03-16 13:56:19.983: E/art(18624): | group="main" sCount=0 dsCount=0 obj=0x740d0000 self=0xb8d93800
03-16 13:56:19.983: E/art(18624): | sysTid=18624 nice=0 cgrp=apps sched=0/0 handle=0xb6efcbec
03-16 13:56:19.983: E/art(18624): | state=R schedstat=( 0 0 0 ) utm=6018 stm=7836 core=1 HZ=100
03-16 13:56:19.983: E/art(18624): | stack=0xbe750000-0xbe752000 stackSize=8MB
03-16 13:56:19.983: E/art(18624): | held mutexes= "mutator lock"(shared held)
03-16 13:56:19.983: E/art(18624): native: #00 pc 00004f60 /system/lib/libbacktrace_libc++.so (UnwindCurrent::Unwind(unsigned int, ucontext*)+23)
03-16 13:56:19.983: E/art(18624): native: #01 pc 00003665 /system/lib/libbacktrace_libc++.so (Backtrace::Unwind(unsigned int, ucontext*)+8)
03-16 13:56:19.983: E/art(18624): native: #02 pc 00256ad1 /system/lib/libart.so (art::DumpNativeStack(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, int, char const*, art::mirror::ArtMethod*)+84)
03-16 13:56:19.983: E/art(18624): native: #03 pc 00238123 /system/lib/libart.so (art::Thread::DumpStack(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const+150)
03-16 13:56:19.983: E/art(18624): native: #04 pc 0023b55b /system/lib/libart.so (art::Thread::ThrowOutOfMemoryError(char const*)+274)
03-16 13:56:19.983: E/art(18624): native: #05 pc 00145a49 /system/lib/libart.so (art::gc::Heap::ThrowOutOfMemoryError(art::Thread*, unsigned int, art::gc::AllocatorType)+832)
03-16 13:56:19.983: E/art(18624): native: #06 pc 00147a09 /system/lib/libart.so (art::gc::Heap::AllocateInternalWithGc(art::Thread*, art::gc::AllocatorType, unsigned int, unsigned int*, unsigned int*, art::mirror::Class**)+668)
03-16 13:56:19.983: E/art(18624): native: #07 pc 0023b9c3 /system/lib/libart.so (art::mirror::Array* art::mirror::Array::Alloc<true>(art::Thread*, art::mirror::Class*, int, unsigned int, art::gc::AllocatorType, bool) (.constprop.210)+898)
03-16 13:56:19.983: E/art(18624): native: #08 pc 0023bf07 /system/lib/libart.so (_jobject* art::Thread::CreateInternalStackTrace<false>(art::ScopedObjectAccessAlreadyRunnable const&) const+230)
03-16 13:56:19.983: E/art(18624): native: #09 pc 0020c7cf /system/lib/libart.so (art::Throwable_nativeFillInStackTrace(_JNIEnv*, _jclass*)+22)
03-16 13:56:19.983: E/art(18624): native: #10 pc 00000c15 /system/framework/arm/boot.oat (Java_java_lang_Throwable_nativeFillInStackTrace__+80)
03-16 13:56:19.983: E/art(18624): at java.lang.Throwable.nativeFillInStackTrace!(Native method)
03-16 13:56:19.983: E/art(18624): at java.lang.Throwable.fillInStackTrace(Throwable.java:166)
03-16 13:56:19.983: E/art(18624): at java.lang.Throwable.<init>(Throwable.java:95)
03-16 13:56:19.983: E/art(18624): at java.lang.Error.<init>(Error.java:48)
03-16 13:56:19.983: E/art(18624): at java.lang.VirtualMachineError.<init>(VirtualMachineError.java:46)
03-16 13:56:19.983: E/art(18624): at java.lang.OutOfMemoryError.<init>(OutOfMemoryError.java:44)
03-16 13:56:19.983: E/art(18624): at dalvik.system.VMRuntime.newNonMovableArray!(Native method)
03-16 13:56:19.983: E/art(18624): at android.graphics.Bitmap.nativeCreate(Native method)
03-16 13:56:19.983: E/art(18624): at android.graphics.Bitmap.createBitmap(Bitmap.java:838)
03-16 13:56:19.983: E/art(18624): at android.graphics.Bitmap.createBitmap(Bitmap.java:798)
03-16 13:56:19.983: E/art(18624): at android.view.View.buildDrawingCacheImpl(View.java:14425)
03-16 13:56:19.983: E/art(18624): at android.view.View.buildDrawingCache(View.java:14357)
03-16 13:56:19.983: E/art(18624): at android.view.View.draw(View.java:14949)
03-16 13:56:19.983: E/art(18624): at android.view.ViewGroup.drawChild(ViewGroup.java:3407)
03-16 13:56:19.983: E/art(18624): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3200)
03-16 13:56:19.983: E/art(18624): at android.view.View.draw(View.java:15252)
03-16 13:56:19.983: E/art(18624): at android.view.View.draw(View.java:15158)
03-16 13:56:19.983: E/art(18624): at android.view.ViewGroup.drawChild(ViewGroup.java:3407)
03-16 13:56:19.983: E/art(18624): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3200)
03-16 13:56:19.983: E/art(18624): at android.view.View.draw(View.java:15252)
03-16 13:56:19.983: E/art(18624): at android.widget.FrameLayout.draw(FrameLayout.java:598)
03-16 13:56:19.983: E/art(18624): at android.view.View.buildDrawingCacheImpl(View.java:14495)
03-16 13:56:19.983: E/art(18624): at android.view.View.buildDrawingCache(View.java:14357)
03-16 13:56:19.983: E/art(18624): at android.view.View.updateDisplayListIfDirty(View.java:14166)
03-16 13:56:19.983: E/art(18624): at android.view.View.getDisplayList(View.java:14207)
03-16 13:56:19.983: E/art(18624): at android.view.View.draw(View.java:14977)
03-16 13:56:19.983: E/art(18624): at android.view.ViewGroup.drawChild(ViewGroup.java:3407)
03-16 13:56:19.983: E/art(18624): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3200)
03-16 13:56:19.983: E/art(18624): at android.view.View.updateDisplayListIfDirty(View.java:14180)
03-16 13:56:19.983: E/art(18624): at android.view.View.getDisplayList(View.java:14207)
03-16 13:56:19.983: E/art(18624): at android.view.View.draw(View.java:14977)
03-16 13:56:19.983: E/art(18624): at android.view.ViewGroup.drawChild(ViewGroup.java:3407)
03-16 13:56:19.983: E/art(18624): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3200)
03-16 13:56:19.983: E/art(18624): at android.view.View.draw(View.java:15252)
03-16 13:56:19.983: E/art(18624): at android.view.View.updateDisplayListIfDirty(View.java:14185)
03-16 13:56:19.983: E/art(18624): at android.view.View.getDisplayList(View.java:14207)
03-16 13:56:19.983: E/art(18624): at android.view.View.draw(View.java:14977)
03-16 13:56:19.983: E/art(18624): at android.view.ViewGroup.drawChild(ViewGroup.java:3407)
03-16 13:56:19.983: E/art(18624): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3200)
03-16 13:56:19.983: E/art(18624): at android.view.View.updateDisplayListIfDirty(View.java:14180)
03-16 13:56:19.983: E/art(18624): at android.view.View.getDisplayList(View.java:14207)
03-16 13:56:19.983: E/art(18624): at android.view.View.draw(View.java:14977)
03-16 13:56:19.983: E/art(18624): at android.view.ViewGroup.drawChild(ViewGroup.java:3407)
03-16 13:56:19.983: E/art(18624): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3200)
03-16 13:56:19.983: E/art(18624): at android.view.View.updateDisplayListIfDirty(View.java:14180)
03-16 13:56:19.983: E/art(18624): at android.view.View.getDisplayList(View.java:14207)
03-16 13:56:19.983: E/art(18624): at android.view.View.draw(View.java:14977)
03-16 13:56:19.983: E/art(18624): at android.view.ViewGroup.drawChild(ViewGroup.java:3407)
03-16 13:56:19.983: E/art(18624): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3200)
03-16 13:56:19.983: E/art(18624): at android.view.View.updateDisplayListIfDirty(View.java:14180)
03-16 13:56:19.983: E/art(18624): at android.view.View.getDisplayList(View.java:14207)
03-16 13:56:19.983: E/art(18624): at android.view.View.draw(View.java:14977)
03-16 13:56:19.983: E/art(18624): at android.view.ViewGroup.drawChild(ViewGroup.java:3407)
03-16 13:56:19.983: E/art(18624): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3200)
03-16 13:56:19.983: E/art(18624): at android.view.View.updateDisplayListIfDirty(View.java:14180)
03-16 13:56:19.983: E/art(18624): at android.view.View.getDisplayList(View.java:14207)
03-16 13:56:19.983: E/art(18624): at android.view.View.draw(View.java:14977)
03-16 13:56:19.983: E/art(18624): at android.view.ViewGroup.drawChild(ViewGroup.java:3407)
03-16 13:56:19.983: E/art(18624): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3200)
03-16 13:56:19.983: E/art(18624): at android.view.View.updateDisplayListIfDirty(View.java:14180)
03-16 13:56:19.984: E/art(18624): at android.view.View.getDisplayList(View.java:14207)
03-16 13:56:19.984: E/art(18624): at android.view.View.draw(View.java:14977)
03-16 13:56:19.984: E/art(18624): at android.view.ViewGroup.drawChild(ViewGroup.java:3407)
03-16 13:56:19.984: E/art(18624): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3200)
03-16 13:56:19.984: E/art(18624): at android.view.View.draw(View.java:15252)
03-16 13:56:19.984: E/art(18624): at android.widget.FrameLayout.draw(FrameLayout.java:598)
03-16 13:56:19.984: E/art(18624): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2650)
03-16 13:56:19.984: E/art(18624): at android.view.View.updateDisplayListIfDirty(View.java:14185)
03-16 13:56:19.984: E/art(18624): at android.view.View.getDisplayList(View.java:14207)
03-16 13:56:19.984: E/art(18624): at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:273)
03-16 13:56:19.984: E/art(18624): at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:279)
03-16 13:56:19.984: E/art(18624): at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:318)
03-16 13:56:19.984: E/art(18624): at android.view.ViewRootImpl.draw(ViewRootImpl.java:2560)
03-16 13:56:19.984: E/art(18624): at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2382)
03-16 13:56:19.984: E/art(18624): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2012)
03-16 13:56:19.984: E/art(18624): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1084)
03-16 13:56:19.984: E/art(18624): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5990)
03-16 13:56:19.984: E/art(18624): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
03-16 13:56:19.984: E/art(18624): at android.view.Choreographer.doCallbacks(Choreographer.java:580)
03-16 13:56:19.984: E/art(18624): at android.view.Choreographer.doFrame(Choreographer.java:550)
03-16 13:56:19.984: E/art(18624): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
03-16 13:56:19.984: E/art(18624): at android.os.Handler.handleCallback(Handler.java:739)
03-16 13:56:19.984: E/art(18624): at android.os.Handler.dispatchMessage(Handler.java:95)
03-16 13:56:19.984: E/art(18624): at android.os.Looper.loop(Looper.java:135)
03-16 13:56:19.984: E/art(18624): at android.app.ActivityThread.main(ActivityThread.java:5343)
03-16 13:56:19.984: E/art(18624): at java.lang.reflect.Method.invoke!(Native method)
03-16 13:56:19.984: E/art(18624): at java.lang.reflect.Method.invoke(Method.java:372)
03-16 13:56:19.984: E/art(18624): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
03-16 13:56:19.984: E/art(18624): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)

和应用程序崩溃。

更新

由于该应用程序是基于以前的 iOS 应用程序。它真的很大,尝试在这里放一些代码很复杂。但我将尝试解释它的组成部分:

首先,它会打开一个选项卡组,我在其中创建了四个不同的选项卡。应用程序创建每个选项卡需要很长时间。

  • 1 标签:这是一个主页标签,它包含指向其他标签的链接。每个链接都是一张图片。我将链接创建为 ImageView。该窗口还包含一个背景图像。 (图片放在ImageView里好还是做成backgroundImage好?对内存和性能有影响吗?)

  • 2、3 和 4 选项卡:包含更多链接和许多子级别。我将解释我为使应用程序崩溃而遵循的过程(每个链接都包含一个带有背景颜色的 View 、一个标签和一个带有 brackgroundGradient 的按钮):

    1. 转到选项卡 2,它会出现一个包含 3 个不同链接的新窗口
    2. 转到链接 1:出现另一个带有 6 个链接的窗口
    3. 转到链接 1:出现另一个带有两个 tableView 的窗口。左边一排(5 行),右边一排大约 20 行。在右表中,每一行都有一个图像和两个添加到 tableviewrow 的标签。

最佳答案

考虑到错误,问题似乎与图片有关:

Unable to load bitmap.

请检查您使用的图像的尺寸。您是否提供特定于 dpi 的变体,以便在较小的设备上您不会加载太大的图像?你会尽可能使用九补丁图像吗?另请注意,在 TabGroup 中,所有主要级别的窗口始终处于打开状态。如果它们都有大图像,您应该使用每个选项卡的 (un)selected 事件来(取消)加载图像。

关于android - 为什么我的带有 TabGroup 的 Titanium Android 应用程序存在内存和性能问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35995635/

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