Android Activity slow on 4.3 device

旧街凉风 提交于 2019-12-20 04:34:34

问题


I developed an app that would stream videos from the web. I have an activity that lists the videos including their icons, titles and status (newly updated). For every row, there is a thumbnail for the video, the video title, and then a "fresh" icon to indicate it's a new upload.

In the emulator, this works relatively fine. In a 2.3 and 4.0.3 HTC Evo devices, it works great. On an HTC One 4.3 device, this activity is really slow. Clicking an item on the list, which takes you to another activity, works fine. Other activities are OK except the list activity.

Here's what I've experimented so far. I have removed the "fresh" icon from the xml, and it worked great. So I assumed it has something to do with this icon. The image is quite large (1000x900px) but only rendered in 50x50dp. I haven't tried downsizing this image to see the performance. But if this is the problem, how come the older HTC phones can render it perfectly.

Only other difference from HTC One and the older HTC phones is that HTC One has an action bar and the older phones use the dedicated menu key in the device.

Is there a way to check the memory usage or processes while running an app in a device to see why it's taking so slow?

UPDATE: I have resized the image to 100x100px, and it's definitely faster. But I still notice there is some lag.

Here's the layout for that list row:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="2dp"
    android:paddingTop="2dp" >

    <ImageView
        android:id="@+id/icon"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true" />

    <ImageView
        android:id="@+id/status"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true" />

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_marginLeft="10dp"
        android:layout_toLeftOf="@id/status"
        android:layout_toRightOf="@id/icon" />
</RelativeLayout>

回答1:


Try to start method profiling (see picture), then launch your activity, then stop method profiling by hitting the same button in the picture again. Eclipse will generate a report where you will see which method takes what time to execute. Thus you can find out which method caused the delay.




回答2:


I noticed performance issues on the HTC one when going from 4.1 to 4.3 or 4.2. Disabling hardware acceleration actually improved performance on many pages when using the HTC One. You can try disabling hardware acceleration in your manifest and then enabling it for all devices but the HTC one in your main activities.

Other devices had great performance for the same pages with hardware acceleration enabled. It's only the HTC one that struggled and needed the below code:

if(!(android.os.Build.MODEL.equalsIgnoreCase("HTC One") && Integer.parseInt(android.os.Build.VERSION.SDK) == 18)) { getWindow().setFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED); }



来源:https://stackoverflow.com/questions/21500947/android-activity-slow-on-4-3-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!