Crash due to Hierarchy view only on Nougat - android

I am facing a crash of my Android app with the stack trace below.
What puzzles me is that the same code with the same variable values (tried with the debugger) does not crash on Android 8 and 9, only on 7.0 / 7.1. The reason is self-explanatory: there's some redrawing triggered from a class (VoipCallsManager) that is not done over the UI thread, but why this is not triggered on newer Android?
E/FatalExceptionKalliope: Uncaught Exception
android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:6898)
at android.view.ViewRootImpl.invalidateChildInParent(ViewRootImpl.java:1083)
at android.view.ViewGroup.invalidateChild(ViewGroup.java:5205)
at android.view.View.invalidateInternal(View.java:13660)
at android.view.View.invalidate(View.java:13624)
at android.view.View.invalidate(View.java:13608)
at android.widget.ImageView.setImageDrawable(ImageView.java:531)
at android.support.v7.widget.AppCompatImageView.setImageDrawable(AppCompatImageView.java:100)
at it.myapp.MainActivity.onSoftPhoneChangeSettings(MainActivity.java:2582)
at it.myapp.stefanotest.VoipCallsManager.isActive(VoipCallsManager.java:187)
at it.myapp.call.MakeCall.executeUseCase(MakeCall.java:53)
at it.myapp.call.MakeCall.executeUseCase(MakeCall.java:15)
at it.myapp.UseCase.run(UseCase.java:40)
at it.myapp.UseCaseHandler$$Lambda$0.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
2019-02-12 19:09:52.340 6961-7055/it.myapp I/intouchste: Uncaught Exception Only the original thread that created a view hierarchy can touch its views.

The stack trace indicates UseCase is a thread and started by the ThreadPoolExecutor, so it is the correct behavior to throw the exception. You can wrap that code with runOnUiThread() to avoid this problem.
However why it doesn't crash on other versions? If you really want to dig to the bottom, you can make a deliberate crash at that place, e.g., divide by zero. So you can have a stack trace on other devices. You can compare with the one you listed here, probably you can find it is not started in a thread.

Related

Android crash happening in some background apps

I'm facing a very annoying android crash that happens in around 1% of PRODUCTION the sessions with the app ALWAYS in the background.
Fatal Exception: android.app.RemoteServiceException: Attempt to invoke virtual method 'int com.android.server.wm.TaskDisplayArea.getDisplayId()' on a null object reference
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2054)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:250)
at android.app.ActivityThread.main(ActivityThread.java:7755)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:958)
From this stack is clear that it comes from an internal android MainLooper operation... but the lack of extra information difficult for me to discover WHAT exactly
does anyone know what is this problem and how to solve it?
There's not a whole lot we can do with this level of information. The only thing I can see is this:
android.app.RemoteServiceException: Attempt to invoke virtual method 'int com.android.server.wm.TaskDisplayArea.getDisplayId()' on a null object reference
At some stage, your code is calling (or using a library which calls) getTaskDisplayArea() in com.android.server.wm. This returns null. It then tries to use this to getDisplayId().
(The rest of the error lines there just indicate it's not in the main thread)
It's likely that wherever you're using the TaskDisplayArea (or the library that calls it) is being called when the UI has been destroyed or has yet to be created.
The rarity indicates it probably is a total background restart of your UI/display elements... if I had to guess maybe caused by Android OS memory cleanup triggers while multitasking, or the user changing orientation repeatedly, etc etc.
If you give more details about where you've used the com.android.server.wm code or layouts you can probably get more help for how to make this background-thread-proof. Depending on what you're actually doing you might end up just catching the exception & retrying later, but some views will allow you to post info to the main thread and I don't know if TaskDisplayArea does.
In my case, I found that the project had a notification icon file in res/drawable-v24/ic_launcher_foreground.xml. The crashing stopped when I moved the .xml associated with v24 in the drawable res folder.

Exception on android side

I'm using crashlytycs and recently i begin to get such exception, but i don't know how to reproduce it on my application.
I know how to fix it. The fix is to use runOnUiThread, but i don't know the point where this exception happens.
When i got exception, i see the line of it in logs, but this one is different, because exception occurs in android class, not mine. Can you give me some advices about where can i search for this exception. I'm not changing ui in asyncTask background. I use volley for networking.
Error Log:
Fatal Exception: android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:7406)
at android.view.ViewRootImpl.invalidateChildInParent(ViewRootImpl.java:1113)
at android.view.ViewGroup.invalidateChild(ViewGroup.java:4595)
at android.view.View.invalidate(View.java:11301)
at android.view.View.invalidate(View.java:11250)
at android.widget.TextView.updateAfterEdit(TextView.java:7817)
at android.widget.Editor.finishBatchEdit(Editor.java:1330)
at android.widget.Editor.endBatchEdit(Editor.java:1313)
at android.widget.TextView.endBatchEdit(TextView.java:6084)
at com.android.internal.widget.EditableInputConnection.endBatchEdit(EditableInputConnection.java:82)
at android.view.inputmethod.BaseInputConnection.finishComposingText(BaseInputConnection.java:292)
at com.android.internal.widget.EditableInputConnection.finishComposingText(EditableInputConnection.java:199)
at android.view.inputmethod.InputMethodManager.checkFocusNoStartInput(InputMethodManager.java:1448)
at android.view.inputmethod.InputMethodManager.onWindowFocus(InputMethodManager.java:1500)
at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:4211)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.os.HandlerThread.run(HandlerThread.java:61)

recycled twice! Runtime Exception in TypedArray

I'm receiving some crash reports from devices using android L preview, the issue is
Caused by: java.lang.RuntimeException: [17, ...... ] recycled twice!
at android.content.res.TypedArray.recycle(TypedArray.java:869)
Can't see the code because Android L is still not available, How can I check if the TypedArray is already recycled?
I actually found that the call to recycle is called twice, but anyway, why throw a exception now breaking potentially old working code (even if it's incorrect to call recycle twice).
Due to changes in TypedArray pooling in L, calling TypedArray.recycle() twice or calling a getter on TypedArray after recycle() is not safe. This has never been correct app behavior and prior to L may have introduced subtle errors.

Android SIGSEV 11 fast scroll of ViewPager

I'm getting
A/libc(26509): Fatal signal 11 (SIGSEGV) at 0x0000000c (code=1), thread 26509 (ct.universaldev)
sometimes when scrolling ViewPager with Fragment's very fast. The app is compatible only with 4.0+ devices, also I don't out of memory (tracked with MAT and Little Eye) and using largeHeap attribute. Also it doesn't look like I'm having memory leaks (at least significant).
I don't receive any Java errors/exceptions before this one. How can I even understand what is the reason if this problem?
I was intercepting touch events in my Fragment subclasses using OnTouchListener attached to their top views. In this listener I was doing some "strange" stuff with event finally storing a local copy of MotionEvent object which was released in OnTouchListener's finalize method. After "decoding" native stacktrace I found out that crashed appeared sometimes on MotionEvent.release() method call. I refactored my code making that OnTouchListener unnecessary and that solved the problem.

Android StackOverflowError?

I write and adapter view to display images, include this I added two extra button to move right and left. I created drawable xml for both button, so while executing code at runtime it's producing following error :
D/AndroidRuntime(3682): Shutting down VM W/dalvikvm( 3682):threadid=1:
thread exiting with uncaught exception (group=0x41bad300)
E/AndroidRuntime(3682): FATAL EXCEPTION: main
E/AndroidRuntime(3682): java.lang.StackOverflowError
E/AndroidRuntime(3682):at android.util.SparseArray.get(SparseArray.java:82)
E/AndroidRuntime(3682):at android.util.SparseArray.get(SparseArray.java:73)
E/AndroidRuntime(3682):at android.content.res.StringBlock.get(StringBlock.java:69)
E/AndroidRuntime(3682):at android.content.res.AssetManager.getResourceValue(AssetManager.java:201)
E/AndroidRuntime(3682):at android.content.res.Resources.getValue(Resources.java:1009)
E/AndroidRuntime(3682):at android.content.res.Resources.getDrawable(Resources.java:658)
E/AndroidRuntime(3682):at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:173)
does any one have idea about it...if I refer normal drawable image then it work properly.
StackOverflowError can happen when too much data is managed in one single task. For example, this could be if you got an endless loop or handling too much data transfer inside a loop. This is one of the reason, there could be more.
see this example of handling stackOverflowError with a database:
http://wiki.webratio.com/index.php/How_to_solve_the_java.lang.StackOverflowError
additionally, I found this post in stackoverflow:
Stack overflows from deep recursion in Java?
But without seeing some code, it´s hard to find the issue, so please post some...

Categories

Resources