I am using BottomsheetDialogFragment and recently getting crash reports on crashlytics, the stacktrace is -
Fatal Exception: java.lang.IllegalStateException: Can not perform this
action after onSaveInstanceState
at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:2044)
at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:2067)
at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:680)
at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:634)
at android.support.v4.app.DialogFragment.dismissInternal(DialogFragment.java:205)
at android.support.v4.app.DialogFragment.dismiss(DialogFragment.java:171)
at com.khaalijeb.inkdrops.ListBanks.onSuccessResponse(ListBanks.java:322)
at com.khaalijeb.inkdrops.App.onSuccessResponse(App.java:800)
at com.olive.upi.OliveUpiManager.onSuccessResponse(Unknown Source:970)
at com.olive.upi.transport.d$33.onResponse(Unknown Source:16)
at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:68)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:169)
at android.app.ActivityThread.main(ActivityThread.java:6595)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
I don't know what caused this error since it is not happening in some device and not all of them. Did anyone face this problem earlier and how to overcome it?
I have tested this particular code 1000 times but never got one but in the production world, I am getting this error in around 2 3 devices.
How to call commitAllowingStateLoss();? will this fixed the problem?
There is BottomsheetDialogFragment#dismissAllowingStateLoss method in the material library that will allow you to fix this problem
Related
I'm getting a "removeView(View) is not supported in AdapterView" exception when running my app in Android version 8.1 and 9.0. In previous versions it runs fine. Although the error is consistent it doesn't happen 100% of the time (which makes me suspect it's a threading issue) nor is it specific to a particular adapter or list view. For instance, I access the same code from multiple actives and it works fine for some and always fails for others. I should also point out that I'm not calling removeView in any of the situations where I get the error. Below is the LogCat output for the exception:
java.lang.UnsupportedOperationException: removeView(View) is not supported in AdapterView
at android.widget.AdapterView.removeView(AdapterView.java:531)
at android.view.ViewOverlay$OverlayViewGroup.add(ViewOverlay.java:195)
at android.view.ViewGroupOverlay.add(ViewGroupOverlay.java:72)
at android.transition.TransitionUtils.createViewBitmap(TransitionUtils.java:170)
at android.transition.TransitionUtils.copyViewImage(TransitionUtils.java:104)
at android.transition.Visibility.onDisappear(Visibility.java:380)
at android.transition.Visibility.createAnimator(Visibility.java:249)
at android.transition.Transition.createAnimators(Transition.java:732)
at android.transition.TransitionSet.createAnimators(TransitionSet.java:396)
at android.transition.Transition.playTransition(Transition.java:1779)
at android.transition.TransitionManager$MultiListener.onPreDraw(TransitionManager.java:315)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:977)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2349)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1392)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6752)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
at android.view.Choreographer.doCallbacks(Choreographer.java:723)
at android.view.Choreographer.doFrame(Choreographer.java:658)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Can anyone point me towards a solution?
I ended up subclassing ListView and overrode removeView and addView with empty methods. I doubt this is the correct way to fix this problem but it worked.
It's a very strange Xiaomi device's OS exception. Even if I do have logs available from Fabric, the stack trace doesn't refer any of my code.
A crash details are below as reported in crashalytics(Fabric),
21K crashes
All crashes on Xiaomi devices
Crashes on Android OS version 6, 7 and 8
Crash Log:
# OS Version: 8.1.0
# Device: Redmi Note 5 pro
# RAM Free: 30.1%
# Disk Free: 74.2%
#0. Crashed: main
at android.widget.Editor.touchPositionIsInSelection(Editor.java:1084)
at android.widget.Editor.performLongClick(Editor.java:1205)
at android.widget.TextView.performLongClick(TextView.java:10908)
at android.view.View.performLongClick(View.java:6360)
at android.view.View$CheckForLongPress.run(View.java:24768)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:171)
at android.app.ActivityThread.main(ActivityThread.java:6606)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:518)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
--
Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.widget.Editor$SelectionModifierCursorController.getMinTouchOffset()' on a null object reference
at android.widget.Editor.touchPositionIsInSelection(Editor.java:1084)
at android.widget.Editor.performLongClick(Editor.java:1205)
at android.widget.TextView.performLongClick(TextView.java:10908)
at android.view.View.performLongClick(View.java:6360)
at android.view.View$CheckForLongPress.run(View.java:24768)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:171)
at android.app.ActivityThread.main(ActivityThread.java:6606)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:518)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
#0. Crashed: main
at android.widget.Editor.touchPositionIsInSelection(Editor.java:1084)
at android.widget.Editor.performLongClick(Editor.java:1205)
at android.widget.TextView.performLongClick(TextView.java:10908)
at android.view.View.performLongClick(View.java:6360)
at android.view.View$CheckForLongPress.run(View.java:24768)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:171)
at android.app.ActivityThread.main(ActivityThread.java:6606)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:518)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
Similar Reference:
https://issuetracker.google.com/issues/37127697
java.lang.NullPointerException with Nougat
Also asked on Xiaomi official forum http://en.miui.com/forum.php?mod=viewthread&tid=4595164
Please do provide any working solution as soon as possible. As users must not be happy with these crashes.
Thanks in advance.
1) First of all, only if required, set one of these.
textView.setMovementMethod(LinkMovementMethod.getInstance());
or
setAutoLinkMask(Linkify.ALL);
or
Linkify.addLinks(textView, Linkify.PHONE_NUMBERS | Linkify.EMAIL_ADDRESSES | Linkify.MAP_ADDRESSES);
2) Secondly, set a long click listener for TextView and it must return true.
textView.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
// do soemthing if needed
return true;
}
});
There is some internal crashing issue on Xiaomi devices. If you override setOnLongClickListener(reference) first and then follow the step one, it will use internal implementation and that will keep on crashing. So it is import to follow above steps in sequence.
I am open to other solutions, however by following this approach I don't see crash reports anymore.
Do you have a custom TextView in your app? Is it perhaps resizeable or has additional functionality?
Xiaomi's Android skin is likely interfering with that, and causing crashes. I suggest trying to long click all TextViews in your app.
It happen when user doing long click on all selected text.
Just define longClickListener:
edit_text.setOnLongClickListener {
doSomething()
true
}
and later you can remove it
edit_text.setOnLongClickListener(null)
For me this crash happened when TextView contained link and setAutoLinkMask(Linkify.ALL); was called for the view. In this case Android handles all clicks (including long clicks) by this view. On devices of other brands link was opened after long click, but on Xiaomi device crash happened. It seems, that they have a bit different logic of handling onTouchEvent inside the TextView. I've played a bit around and found, that setting android:textIsSelectable="false" for the TextView in layout file solves the problem.
I know, that it's not scalable solution, but for my case it was perfect, so I stopped investigating further. Maybe it will give a hint to someone else.
My application does image detection using arcore augmentedimages and shows a viewrenderable once the image detected. If i close the app after the image has been detected and viewrenderable is shown, then reopen the application, the app crashes once the image is detected, throwing
IllegalStateException: Cannot use the same ViewRenderable with
multiple SceneViews
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.techaffinity.arroutertroubleshoot, PID: 4313
java.lang.IllegalStateException: Cannot use the same ViewRenderable with multiple SceneViews.
at com.google.ar.sceneform.rendering.RenderViewToExternalTexture.attachView(RenderViewToExternalTexture.java:131)
at com.google.ar.sceneform.rendering.ViewRenderable.attachToRenderer(ViewRenderable.java:303)
at com.google.ar.sceneform.rendering.RenderableInstance.attachToRenderer(RenderableInstance.java:81)
at com.google.ar.sceneform.Node.activate(Unknown Source)
at com.google.ar.sceneform.Node.updateActiveStatusRecursively(Unknown Source)
at com.google.ar.sceneform.Node.setEnabled(Unknown Source)
at com.techaffinity.arroutertroubleshoot.augmentedImage.HighlightNode.setVisible(HighlightNode.java:65)
at com.techaffinity.arroutertroubleshoot.augmentedImage.ModelNode.setChildVisible(ModelNode.java:69)
at com.techaffinity.arroutertroubleshoot.augmentedImage.ARTroubleshootActivity.yesPressed(ARTroubleshootActivity.java:178)
at com.techaffinity.arroutertroubleshoot.augmentedImage.ARTroubleshootActivity.lambda$TWxn4Gt1IyJ444bAiIcNiVnU0ng(ARTroubleshootActivity.java)
at com.techaffinity.arroutertroubleshoot.augmentedImage.-$$Lambda$ARTroubleshootActivity$TWxn4Gt1IyJ444bAiIcNiVnU0ng.onClick(lambda)
at android.view.View.performClick(View.java:5640)
at android.view.View$PerformClick.run(View.java:22455)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6165)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)
crash occurs at onUpdateFrame method at
node.setRenderable(viewRenderableCF);
arFragment.getArSceneView().getScene().addChild(node);
where 'viewRenderableCF' is CompletableFuture of type ViewRenderable
I am currently overcoming this problem by calling System.exit(0) in ondestroy() method.
Is there any better way to do this(clearing app from memory like swiping away the app preview in recent apps list)?
or
Is there any code related to arcore to clear out the instance of SceneView?
try call this onDestroy/OnPause
arFragment.getArSceneView().getScene().onRemoveChild(node);
Making the CompletableFuture null in the onDestroy() callback of the activity solves the problem. Even after the finish method is called the CompletableFuture of type ViewRenderable is still in the memory. When I go to the same activity again, the ViewRenderable is created from the old CompletableFuture. This is also the case for CompletableFuture of type ModelRenderable but for reasons I don't know, setting modelrenderable to the node doesn't cause this crash.
It may be a red herring, but my app is full of UI-less task fragments to perform most network operations and work around the activity lifecycle. An example of this type of architecture is described here. https://stackoverflow.com/a/12303649/2662474
On new Google Pixel and Nexus phones running Oreo 8.0, the app has started crashing on resume of many different activities in a way that is very difficult to debug and seems like a low level Android bug that was introduced. It is not happening on any previous OS versions.
Fatal Exception: java.lang.RuntimeException: Unable to resume activity {com.mycompany.shop/com.mycompany.shop.activity.MainNavActivity}: java.lang.IndexOutOfBoundsException: Index: 3, Size: 3
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3645)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3685)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1643)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by java.lang.IndexOutOfBoundsException: Index: 3, Size: 3
at java.util.ArrayList.get(ArrayList.java:437)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1610)
at android.app.FragmentManagerImpl.dispatchMoveToState(FragmentManager.java:3035)
at android.app.FragmentManagerImpl.dispatchResume(FragmentManager.java:3001)
at android.app.FragmentController.dispatchResume(FragmentController.java:200)
at android.app.Activity.performResume(Activity.java:7100)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3620)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3685)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1643)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Please help!
Your error is occurring in the method moveToState() of the nested class FragmentManagerImpl in FragmentManager. The specific code that is causing the erorr is Fragment f = mAdded.get(i) in the following lines:
final int numAdded = mAdded.size();
for (int i = 0; i < numAdded; i++) {
Fragment f = mAdded.get(i); // [causing the error]
moveFragmentToExpectedState(f);
if (f.mLoaderManager != null) {
loadersRunning |= f.mLoaderManager.hasRunningLoaders();
}
}
mAdded is a list of added fragment and is defined as:
ArrayList<Fragment> mAdded;
When the error occurs, i == 3 and the size of the mAdded Arraylist is something less than that. (Error line: "java.lang.IndexOutOfBoundsException: Index: 3, Size: 3") For this to occur, a fragment must have been removed from mAdded somewhere within this for-loop, specifically somewhere in the call chain starting with moveFragmentToExpectedState().
You mention that your app is "work[ing] around the activity lifecycle." Maybe you are getting a fragment into an unexpected state according the Oreo 8.0. I suggest that you put your app into the debugger and set a breakpoint in this for loop. You can then try to track down where the Arraylist mAdded is being changed. That should at least point you in the right direction for the solution.
btw, the source code for API 26 has been released. It can help you in debugging.
Update: From looking at the source, that area of FragmentManger in API 26 has received substantial work from the version in API 25. You may want to take azizbekian's suggestion and move to android.support.v4.app.Fragment. The support version seems to be more in line with API 25 than API 26. This could be a stop-gap measure until you can figure out the root cause.
Regarding your current implementation, I would look for anything that would remove or detach a fragment during the onResume() processing, especially if it is done off the UI thread and maybe in a non thread-safe manner. Look for anything that invoke, directly or indirectly, removeFragment() or detachFragment() of FragmentManager since these seem to be the only places where fragments are removed from mAdded.
Did you try this?: Nesting fragments inside a viewpager fragment throws IndexOutOfBoundsException
You may using getSupportFragmentManager() to call remove().
So, change getSupportFragmentManager() to YourFragment.this.getFragmentManager()
Linked answer said:
Change
getActivity().getSupportFragmentManager().beginTransaction().remove(instance).commit();
to
ThisFragment.this.getFragmentManager().beginTransaction().remove(instance).commit();
I tried to make an app can draw all the touching points when users touching their own device. (it's mean that even outside the app.)
At first, I add a view overlay on the device. But if I fetch the touch points on the top of screen, it seems to block the entire screen and I can't let the touch get through the view to touch other unit under the view.
At second, I write "show_touches" settings of system, then I can see all the touch points.
The second way worked fine until android 6.0 release. Above 6.0, I need to request permission again in the app. But when the permission granted, I still get a crash "You cannot change private secure settings".
Is there any way to get secure settings permission? Or another way to draw touch points on the top of screen?
I need an answer without rooted, can anyone help me figure it out?
this is my stacktrace:
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.morshues.mytestapp, PID: 31194
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=45487, result=-1, data=Intent { (has extras) }} to activity {com.morshues.mytestapp/com.morshues.mytestapp.SecondActivity}: java.lang.IllegalArgumentException: You cannot change private secure settings.
at android.app.ActivityThread.deliverResults(ActivityThread.java:3988)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4038)
at android.app.ActivityThread.access$1400(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1443)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:168)
at android.app.ActivityThread.main(ActivityThread.java:5845)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
Caused by: java.lang.IllegalArgumentException: You cannot change private secure settings.
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:165)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
at android.content.ContentProviderProxy.call(ContentProviderNative.java:646)
at android.provider.Settings$NameValueCache.putStringForUser(Settings.java:1400)
at android.provider.Settings$System.putStringForUser(Settings.java:1769)
at android.provider.Settings$System.putIntForUser(Settings.java:1874)
at android.provider.Settings$System.putInt(Settings.java:1868)
at com.morshues.FullRecorder.start(FullRecorder.java:238)
at com.morshues.FullRecorder.onActivityResult(FullRecorder.java:132)
at com.morshues.mytestapp.onActivityResult(MainCenter.java:130)
at com.morshues.mytestapp.SecondActivity.onActivityResult(SecondActivity.java:91)
at android.app.Activity.dispatchActivityResult(Activity.java:6439)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3984)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4038)
at android.app.ActivityThread.access$1400(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1443)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:168)
at android.app.ActivityThread.main(ActivityThread.java:5845)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)