Google Play shows a lot of crash reports caused by WindowManager$BadTokenException.
Full log:
java.lang.RuntimeException:
at android.app.ActivityThread.handleServiceArgs (ActivityThread.java:3344)
at android.app.ActivityThread.-wrap21 (ActivityThread.java)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1583)
at android.os.Handler.dispatchMessage (Handler.java:102)
at android.os.Looper.loop (Looper.java:154)
at android.app.ActivityThread.main (ActivityThread.java:6121)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:889)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:779)
Caused by: android.view.WindowManager$BadTokenException:
at android.view.ViewRootImpl.setView (ViewRootImpl.java:679)
at android.view.WindowManagerGlobal.addView (WindowManagerGlobal.java:342)
at android.view.WindowManagerImpl.addView (WindowManagerImpl.java:93)
at android.app.Dialog.show (Dialog.java:329)
at android.app.AlertDialog$Builder.show (AlertDialog.java:1112)
at com.nutomic.syncthingandroid.activities.SyncthingActivity.showLoadingDialog (SyncthingActivity.java:142)
at com.nutomic.syncthingandroid.activities.SyncthingActivity.onApiChange (SyncthingActivity.java:88)
at com.nutomic.syncthingandroid.activities.SyncthingActivity.access$lambda$1 (SyncthingActivity.java)
at com.nutomic.syncthingandroid.activities.SyncthingActivity$$Lambda$2.onApiChange (Unknown Source)
at com.nutomic.syncthingandroid.service.SyncthingService.onApiChange (SyncthingService.java:530)
at com.nutomic.syncthingandroid.service.SyncthingService.updateState (SyncthingService.java:246)
at com.nutomic.syncthingandroid.service.SyncthingService.onStartCommand (SyncthingService.java:181)
at android.app.ActivityThread.handleServiceArgs (ActivityThread.java:3327)
Relevant code:
if (isFinishing() || mLoadingDialog != null)
return;
LayoutInflater inflater = getLayoutInflater();
View dialogLayout = inflater.inflate(R.layout.dialog_loading, null);
TextView loadingText = (TextView) dialogLayout.findViewById(R.id.loading_text);
loadingText.setText((getIntent().getBooleanExtra(EXTRA_FIRST_START, false))
? R.string.web_gui_creating_key
: R.string.api_loading);
mLoadingDialog = new AlertDialog.Builder(this)
.setCancelable(false)
.setView(dialogLayout)
.show();
What could be the cause of this crash? It would also help if I had a way to reproduce the crash. The full source of the app is available on Github.
Such a problem might occur if the app is closing, or is in the background somehow.
You should check if your activity is not being closed (for example, onDestroy was called), and that it is active in the foreground (and visible).
There are several options for how to check if it is in the background, here's one that should work:
RunningAppProcessInfo myProcess = new RunningAppProcessInfo();
ActivityManager.getMyMemoryState(myProcess);
isInBackground = myProcess.importance != RunningAppProcessInfo.IMPORTANCE_FOREGROUND;
Okay I found the problem. In my code I was doing something like this (in a much more complicated way):
if (isFinishing())
return;
new AlertDialog.Builder(this).show();
Thread.sleep(1000);
The show() method call finished normally, but the dialog was only attached to the Activity after the sleep was finished. So if you have this problem, make sure you're not doing any long-running operation on the main thread.
Related
I got following crash report:
java.lang.NullPointerException:
at com.myapp.actions.SellAction.getAction (SellAction.java:16)
at com.myapp.handler.SellHandler.sell (SellHandler.java:169)
at com.myapp.main.MyActivity.sell (MyActivity.java:537)
at com.myapp.main.Fragment2.lambda$onCreateView$0 (Fragment2.java:31)
at com.myapp.main.Fragment1$$InternalSyntheticLambda$1$c14fd7a0fe0c17e220e277448d1b71579f8038a9784d642f5a2e5b6a00f377eb$2.onClick$bridge (Fragment1.java)
at android.view.View.performClick (View.java:7862)
at android.widget.TextView.performClick (TextView.java:15004)
at android.view.View.performClickInternal (View.java:7831)
at android.view.View.access$3600 (View.java:879)
at android.view.View$PerformClick.run (View.java:29359)
at android.os.Handler.handleCallback (Handler.java:883)
at android.os.Handler.dispatchMessage (Handler.java:100)
at android.os.Looper.loop (Looper.java:237)
at android.app.ActivityThread.main (ActivityThread.java:8167)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:496)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1100)
The code from Fragment2.lambda$onCreateView$0 (Fragment2.java:31) to SellAction.getAction is a valid stacktrace in my code. But usually (I don't see how this is possible) the Fragment1 (Fragment1$$InternalSyntheticLambda$1$c14fd7a0fe0c17e220e277448d1b71579f8038a9784d642f5a2e5b6a00f377eb$2.onClick$bridge (Fragment1.java)) has nothing to do with that code and I have no idea how it appears there. I don't know if that has something to do with the InternalSyntheticLambda. But I do not find anything about that on the internet (10 search results at google). Does anyone here has an idea what that is or how that can happen?
Looks like some handler or listener is leaking.
Try to look through all the call chain between
at com.myapp.actions.SellAction.getAction (SellAction.java:16)
and
at com.myapp.main.Fragment2.lambda$onCreateView$0 (Fragment2.java:31)
There might be view or some other object that is set up with listener which is not dropped correctly on view destroy. Special attention to Fragment2#onCreateView line 31.
I am trying to paste text using ClipData on Android. The following code gives a java.lang.SecurityException. This does not happen all of the time. Should I declare any uses-permission to read the clipboard?
java.lang.RuntimeException:
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2750)
at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2811)
at android.app.ActivityThread.-wrap12 (ActivityThread.java)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1528)
at android.os.Handler.dispatchMessage (Handler.java:102)
at android.os.Looper.loop (Looper.java:154)
at android.app.ActivityThread.main (ActivityThread.java:6316)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:872)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:762)
Caused by: java.lang.SecurityException:
at android.os.Parcel.readException (Parcel.java:1683)
at android.database.DatabaseUtils.readExceptionFromParcel (DatabaseUtils.java:183)
at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel (DatabaseUtils.java:146)
at android.content.ContentProviderProxy.openTypedAssetFile (ContentProviderNative.java:692)
at android.content.ContentResolver.openTypedAssetFileDescriptor (ContentResolver.java:1163)
at android.content.ContentResolver.openTypedAssetFileDescriptor (ContentResolver.java:1107)
at android.content.ClipData$Item.coerceToText (ClipData.java:332)
at br.com.sicoob.camera.clipboard.ClipboardInterface.getText (ClipboardInterface.java:35)
at br.com.sicoobnet.InicioWap.verificarExisteBoletoCopiado (InicioWap.java:312)
at br.com.sicoobnet.InicioWap.verificarAcao (InicioWap.java:308)
at br.com.sicoobnet.InicioWap.onCreate (InicioWap.java:126)
at android.app.Activity.performCreate (Activity.java:6757)
at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2703)
This question is fixed to my project, but to everyone who whants to know, this is how I fix.
First I figured out when this error happens. It was when I don't have any text in clipboard and my application tried to go to external storage and the error was thrown.
Then to fix that I just change my method to verify has a text inside clipboard.
It was like that:
ClipboardManager clipboard = getManager(context);
ClipData clip = clipboard.getPrimaryClip();
return clip != null && clip.getItemCount() > 0;
Then it was like that:
ClipboardManager clipboard = getManager(context);
clipboard.getPrimaryClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN);
The Google Developer Console shows that my app has received two of the same errors in the past month, but this RuntimeException doesn't specify a class or file for which the error stems from. There's nothing specific that I can see. Below are the error for two different devices:
Samsung Galaxy S8 Active (cruiserlteatt), 4096MB RAM, Android 7.0
Report 1 of 2
java.lang.RuntimeException:
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2984)
at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3045)
at android.app.ActivityThread.handleRelaunchActivity
(ActivityThread.java:4978)
at android.app.ActivityThread.-wrap21 (ActivityThread.java)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1648)
at android.os.Handler.dispatchMessage (Handler.java:102)
at android.os.Looper.loop (Looper.java:154)
at android.app.ActivityThread.main (ActivityThread.java:6781)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1410)
Samsung Galaxy S7 (heroqltespr), 4096MB RAM, Android 7.0
Report 2 of 2
java.lang.RuntimeException:
at android.app.ActivityThread.performLaunchActivity
(ActivityThread.java:2947)
at android.app.ActivityThread.handleLaunchActivity
(ActivityThread.java:3008)
at android.app.ActivityThread.handleRelaunchActivity
(ActivityThread.java:4974)
at android.app.ActivityThread.-wrap21 (ActivityThread.java)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1656)
at android.os.Handler.dispatchMessage (Handler.java:102)
at android.os.Looper.loop (Looper.java:154)
at android.app.ActivityThread.main (ActivityThread.java:6688)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1358)
What could it be causing this error? These are the only two times it happened, and the log provided doesn't show a java class or xml file like other errors I am able to resolve.
Would greatly appreciate it if someone could help me resolve this,
many thanks.
According to the source code, here are two places in ActivityThread.performLaunchActivity where RuntimeException is thrown. They are:
} catch (Exception e) {
if (!mInstrumentation.onException(activity, e)) {
throw new RuntimeException(
"Unable to instantiate activity " + component
+ ": " + e.toString(), e);
}
}
and
} catch (Exception e) {
if (!mInstrumentation.onException(activity, e)) {
throw new RuntimeException(
"Unable to start activity " + component
+ ": " + e.toString(), e);
}
}
As you can see:
They both provide a message for the RuntimeException that includes the exception message from the original exception.
They both pass the original exception (e) to the RuntimeException constructor so that it is properly chained.
Without the causal exception message (at least) and the causal exception stacktrace, OR your complete app source code, it is going to be next to impossible to diagnose your problem.
You need to figure out how to get the Google Developer Console to give you the missing info, or get logcat to log them. We can't help you without that missing info.
Apart from that, I can advise you that the best way to try to diagnose problems like this is to look at the Android source code. (It is not very helpful here ... but it would be if you had the missing diagnostic information.)
I've recently published my app on Google Play. I'm checking out the crashes from Firebase and one of the clusters with the highest number of exceptions is a fatal exception with the following stack trace:
Caused by android.renderscript.RSIllegalArgumentException: Unsuported element type.
android.renderscript.ScriptIntrinsicBlur.create (ScriptIntrinsicBlur.java:50)
com.kayimapps.autocolorsplash_android.Util.getBlurredBitmap (Util.java:234)
com.kayimapps.autocolorsplash_android.activities.IntroActivity.onCreate (IntroActivity.java:83)
android.app.Activity.performCreate (Activity.java:5283)
android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1097)
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2209)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2299)
android.app.ActivityThread.access$700 (ActivityThread.java:150)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1280)
android.os.Handler.dispatchMessage (Handler.java:99)
android.os.Looper.loop (Looper.java:137)
android.app.ActivityThread.main (ActivityThread.java:5283)
java.lang.reflect.Method.invokeNative (Method.java)
java.lang.reflect.Method.invoke (Method.java:511)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1102)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:869)
dalvik.system.NativeStart.main (NativeStart.java)
The getBlurredBitmap method that can be seen in the stack trace is also as follows:
public static Bitmap getBlurredBitmap(Bitmap input, Context context)
{
Bitmap result = null;
try {
RenderScript rsScript = RenderScript.create(context);
Allocation alloc = Allocation.createFromBitmap(rsScript, input);
ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rsScript, alloc.getElement());
blur.setRadius(25);
blur.setInput(alloc);
result = Bitmap.createBitmap(input.getWidth(), input.getHeight(), input.getConfig());
Allocation outAlloc = Allocation.createFromBitmap(rsScript, result);
blur.forEach(outAlloc);
outAlloc.copyTo(result);
rsScript.destroy();
}
catch (RSIllegalArgumentException e)
{
FirebaseCrash.report(e);
}
return result;
}
I've looked everywhere for this exception to see its cause but so far I've found nothing. The interesting thing is that this exception is raised only in devices with Android 17 (4.2), and the only device I'm testing the app with is a Samsung Galaxy S3 with Android 17, which raises no exceptions on that exact same place.
I'm guessing that since RenderScript runs on GPU, maybe some devices simply don't support it because of their hardware. The devices that raise this exception are all sorts of devices with all sorts of brands though, so I can't really blame it on one manufacturer.
Does anyone have any idea on why this would happen, or maybe some pointers on where to look for the solution?
Edit: Turns out I am an idiot and the OS version of the phone I'm using is 18, not 17. The problems still persists on devices with Android 17 though.
I cannot seem to make head or tail from the stack trace eclipse is giving me. The code used to work. I am not sure what I changed. But now when I launch the dialog fragment, the app crashes with the following error log.
FATAL EXCEPTION: main
Process: com.company.appname, PID: 8962
java.lang.NullPointerException
at android.support.v4.app.DialogFragment.onActivityCreated(DialogFragment.java:366)
at android.support.v4.app.Fragment.performActivityCreated(Fragment.java:1508)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:958)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1115)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1478)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:446)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5579)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)
My code is massive so I am not sure which portion to show. So maybe someone has seen this mysterious kind of crash with apparently no root in my code (i.e. since eclipse is not naming one)
UPDATE
Ok. I find the culprit. But I still don’t know how to fix it. So I have CatDialog (the one that’s crashing now) and FacebookDialog. So I have had these two DialogFragments working independently. But now I am launching FacebookDialog from inside the onCreateView method of the CatDialog. That is the reason for the crash. The launching is conditional as the following code shows
protected void requestFaceBookPublishPermission() {
Log.i(TAG, "going into requestFaceBookPublishPermission");
Session session = Session.getActiveSession();
if (session == null || !session.isOpened() ||
!session.isPermissionGranted(FacebookDialog.PERMISSION)) {
FacebookDialog fb = new FacebookDialog();
fb.show(getChildFragmentManager(), "fb");
dismiss();
}
Log.i(TAG, "leaving requestFaceBookPublishPermission");
}
You are calling dismiss() from inside requestFaceBookPublishPermission and that's totally wack! You can't do that if you are calling it from inside onCreateView of another DialogFragment. So you seed to keep the two separated again. But great question though.
So understand what you are doing: you are dismissing before returning the view inside onCreateView. You are pre-empting.
I've encountered this issue before. Then I was dismissing the dialog inside oncreateView and I was getting NullpointerException. Then I moved my code to dismiss the dialog to onResume() and the issue was fixed!
Wrong
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_home, container, false);
if(something){
} else{
dismiss(); //Dismissing dialog here gives NullpointerException
}
}
return view;
Correct
#Override
public void onResume() {
super.onResume();
if(something){
} else{
dismiss();
}
}