3

After 2 days of fruitless testing, I've decided to post my issue here, in the hopes that I'm missing something obvious.

I've boiled down a seemingly innocuous xml-layout to a random collection of images, layouts, and a scrollview. Here it is:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/wood_texture"
    tools:context="com.testlayout.example.testlayout.MainActivity">

    <ImageView
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:src="@drawable/image_one"
        android:id="@+id/imageOne"
        android:adjustViewBounds="true"
        android:layout_gravity="center_vertical"
        android:visibility="visible"/>

    <ImageView
        android:layout_width="300dp"
        android:layout_height="150dp"
        android:background="@drawable/dark_wood_texture"
        android:id="@+id/darkWood"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginBottom="20dp"
        android:visibility="visible"/>

    <HorizontalScrollView
        android:layout_width="300dp"
        android:layout_height="150dp"
        android:id="@+id/handScrollView"
        android:scrollbars="none"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        android:paddingTop="10dp"
        android:paddingBottom="10dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginBottom="20dp"
        android:visibility="visible">

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:id="@+id/handLayout">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:src="@drawable/image_three"
                android:id="@+id/imageView"
                android:adjustViewBounds="true"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"/>

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:src="@drawable/image_three"
                android:id="@+id/imageView2"
                android:adjustViewBounds="true"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"/>

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:src="@drawable/image_three"
                android:id="@+id/imageView6"
                android:adjustViewBounds="true"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"/>

        </LinearLayout>

    </HorizontalScrollView>

    <ImageView
        android:id="@+id/imageTwo"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:src="@drawable/image_two_tiled"
        android:scaleType="fitXY"/>
</RelativeLayout>

I can load this layout onto my phone just fine, but after swiping around in the scrollview for as little as 5 seconds, the app will suddenly crash to the home screen - without reporting that the app has stopped working. I've been testing on a Samsung Galaxy s6. I've also tested this on a Samsung Galaxy Tab 2, where this problem does not occur (both my real app and this test app run just fine on the tablet).

I've created a new Android Studio project; the only changes I've made are to the res/layout/activity_main.xml, as outlined above. I've also included the drawables I'm using. I'm hoping someone with better debugging skills than I can either pull down that project, or simply create a new one of their own using the above layout (that's all there is to it, though you'll need my drawables regardless).

I'd like to clarify that I'm not looking for a way to fix this issue, I'm trying to understand the issue. The thing is, after 2 days of testing, I've found half a dozen ways to seemingly "fix" the issue. But none of them make any sense, and they all seem unrelated. If I don't know why my solution fixes the issue, I won't know how to avoid it during future development.

Observations

As I mentioned above, I've found several ways to "fix" the issue (i.e. make it no longer crash), but none of them seem to be related. Here are a few:

  • Set the visibility of almost any of the elements to gone.
  • Remove the background from the root element.
  • Remove the line android:tileMode="repeat" from drawable/image_two_tiled.xml
    • Note that changing the tileMode to something else - for instance, clamp - does not fix the issue. Only removing it (or setting it to disabled).
  • Set the src of the ImageView with the id "@+id/imageTwo" to image_two_smaller_tiled.
    • This is the exact same image as image_two_tiled, just a smaller resolution.

This is by no means an exhaustive list of, but it gives you an idea of how disjointed these fixes are (especially the tileMode one).

As near as I can tell, it looks like some kind of memory issue. I'm fairly new to android development, so I'm not quite familiar with the memory constraints I need to work with, but I would be horrifically concerned if I was causing the heap to explode with so few images, and of fairly small size (at the very least, certainly not big).

If anyone could tell me exactly what is causing my app to crash, I would be. . . Well, I would be extremely grateful. 'Cause after 2 days of trying to debug this myself, I'm about ready to quit android development : (

Edit

The app itself does not throw an exception, however logcat does consistently show this error at the time of the crash when I'm not filtering log messages from my app alone.

E/Resources: RunTimeException
android.content.res.Resources$NotFoundException: Resource ID #0x7f0202cf
    at android.content.res.Resources.getValue(Resources.java:2558)
    at android.content.res.Resources.startRC(Resources.java:1116)
    at android.app.ActivityThread$mRunnable.run(ActivityThread.java:3056)
    at java.lang.Thread.run(Thread.java:818)

e2: I'm starting to wonder if this is an issue with my phone, and not the app, since I can run it just fine on my tablet. I'd really like to know if anyone else is experiencing this issue if they try to run this on their Galaxy s6. Specifically the S6 - that would tell me if it's an issue with my phone or all S6's in general.

Community
  • 1
  • 1
Whelch
  • 2,003
  • 2
  • 11
  • 14
  • What is the exception shown after crashing? – Joshua Sep 20 '16 at 04:27
  • @Joshua Edited to include a possible culprit. The app itself does not throw any exceptions. – Whelch Sep 20 '16 at 04:37
  • Do you resolve the exception? It says you can a non-existing resources id. – Joshua Sep 20 '16 at 04:40
  • It's one of " mystery bacteria" issue where you can fix it but dint know what happen.. i faced it many times .. okay so from where should we start fixing issue or rootb of it? – DevKRos Sep 20 '16 at 04:42
  • @Joshua that resource id does not exist within my application. But nor am I referencing it anywhere - that exception is being thrown from outside of my app. – Whelch Sep 20 '16 at 04:55
  • Go to R file and identify the resource by search. And post it here. – Ganesh Kanna Sep 20 '16 at 04:59
  • @GKTHEBOSS that resourceID doesn't exist. I did a text-search on the whole project and nothing came back. – Whelch Sep 20 '16 at 05:01
  • Not in whole project. clear all compilation issue. Rebuild the project. Run once again. You will get crash again. Now go to R file search the identifier causing the issue. – Ganesh Kanna Sep 20 '16 at 05:03
  • A different resource ID was mentioned when i ran it. It pointed to this: `int layout abc_action_menu_layout 0x7f030004` – Whelch Sep 20 '16 at 05:04
  • that may related Android app combat . Theme is the problem i guess – Ganesh Kanna Sep 20 '16 at 05:19

1 Answers1

0

This previous SO post answer solved my issue.

In short, it was the BitmapDrawable that was causing the entire issue. While unfortunately I cannot say why this fixes the issue, setting the view that uses the bitmap with layerType="software" will prevent the crashes.

  • In a layout: android:layerType="software"
  • In code: view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
Community
  • 1
  • 1
Whelch
  • 2,003
  • 2
  • 11
  • 14