when i am using facebook login button in my activity, logcat shows up this. I don't get it why this showing up I checked entire class never found a reference.
06-27 14:17:45.819 12019-12019/com.ets.medecord E/WindowManager﹕ Activity com.facebook.FacebookActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#4054a518 that was originally added here
android.view.WindowLeaked: Activity com.facebook.FacebookActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#4054a518 that was originally added here
at android.view.ViewRoot.<init>(ViewRoot.java:259)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
at android.view.Window$LocalWindowManager.addView(Window.java:465)
at android.app.Dialog.show(Dialog.java:241)
at com.facebook.internal.WebDialog$DialogWebViewClient.onPageStarted(WebDialog.java:500)
at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:264)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3835)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
at dalvik.system.NativeStart.main(Native Method)
to check out activity code http://pastebin.com/qQqbvX6g
Window leak exception often occurs if Dialog not used properly(such as not finished before jumping to another activity). And Google has reminded developers that DialogFragment is a better choice than Dialog.
Related
I am getting a TransactionTooLargeException at (what seem to be) random points throughout my application as follows:
E/AndroidRuntime(19472): FATAL EXCEPTION: main
E/AndroidRuntime(19472): java.lang.RuntimeException: Adding window failed
E/AndroidRuntime(19472): at android.view.ViewRootImpl.setView(ViewRootImpl.java:498)
E/AndroidRuntime(19472): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:313)
E/AndroidRuntime(19472): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:215)
E/AndroidRuntime(19472): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:140)
E/AndroidRuntime(19472): at android.view.Window$LocalWindowManager.addView(Window.java:537)
E/AndroidRuntime(19472): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2521)
E/AndroidRuntime(19472): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2000)
E/AndroidRuntime(19472): at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3365)
E/AndroidRuntime(19472): at android.app.ActivityThread.access$700(ActivityThread.java:128)
E/AndroidRuntime(19472): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1165)
E/AndroidRuntime(19472): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(19472): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(19472): at android.app.ActivityThread.main(ActivityThread.java:4514)
E/AndroidRuntime(19472): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(19472): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(19472): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
E/AndroidRuntime(19472): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
E/AndroidRuntime(19472): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(19472): Caused by: android.os.TransactionTooLargeException
E/AndroidRuntime(19472): at android.os.BinderProxy.transact(Native Method)
E/AndroidRuntime(19472): at android.view.IWindowSession$Stub$Proxy.add(IWindowSession.java:516)
E/AndroidRuntime(19472): at android.view.ViewRootImpl.setView(ViewRootImpl.java:488)
E/AndroidRuntime(19472): ... 17 more
I mainly get this exception thrown at me when i try to display a dialog or manually open an action bar menu, but it seems to be really picky about when it happens: I can use the application for a couple minutes without issues and it suddenly happens, but i've also experienced it right away as soon as i open my application.
Any ideas are deeply welcomed.
EDIT:
Similar questions always mention a service, which i do have. I have an authenticator service that exchanges really light payloads consisting mostly of an intent and auth credentials. Shouldn't be too bad on the transaction buffer but i'd have to profile that somehow.
This can happen with no service involved, just passing large object graphs to another activity via Intent. Maybe a blog post I just wrote can help you understand the issue.
We're seeing quite a few of these exceptions in our crash logging tool.
The stacktrace contains only android functions:
android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy#4150fa88 is not valid; is your activity running?
at android.view.ViewRootImpl.setView(ViewRootImpl.java:646)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:248)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2964)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
at android.app.ActivityThread.access$600(ActivityThread.java:156)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1340)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:153)
at android.app.ActivityThread.main(ActivityThread.java:5297)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(NativeStart.java)
How would you proceed with finding the cause of this?
We can't get more information than this I'm afraid.
My guess is we're trying to show a popup or something after the activity has died.
This is usually linked to keeping references to a dead Context or starting a Dialog with the wrong Context.
I have integrated zxing barcode scanner in my app. When the scanner gets a scan it takes the result and searches an external online database via a async task then opens a new activity based on the results. I am getting a force close that is not consistent, it does not happen every scan, only sometimes so I am having trouble figuring out why I am getting a leaked window error, and only sometimes:
09-25 21:02:48.105 24371-24371/com.beerportfolio.beerportfoliopro E/WindowManager﹕ Activity com.example.beerportfoliopro.BeerPage2 has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#424b7198 that was originally added here
android.view.WindowLeaked: Activity com.example.beerportfoliopro.BeerPage2 has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#424b7198 that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:468)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:419)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:351)
at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:171)
at android.view.Window$LocalWindowManager.addView(Window.java:558)
at android.app.Dialog.show(Dialog.java:282)
at com.example.beerportfoliopro.GetBeerRateJSON.onPreExecute(GetBeerRateJSON.java:52)
at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
at android.os.AsyncTask.execute(AsyncTask.java:534)
at com.example.beerportfoliopro.GetBeerDataJSON.onPostExecute(GetBeerDataJSON.java:111)
at com.example.beerportfoliopro.GetBeerDataJSON.onPostExecute(GetBeerDataJSON.java:34)
at android.os.AsyncTask.finish(AsyncTask.java:631)
at android.os.AsyncTask.access$600(AsyncTask.java:177)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5536)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1074)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:841)
at dalvik.system.NativeStart.main(Native Method)
09-25 21:02:48.265 24371-24371/com.beerportfolio.beerportfoliopro E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.IllegalArgumentException: View not attached to window manager
at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:784)
at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:476)
at android.view.WindowManagerImpl$CompatModeWrapper.removeView(WindowManagerImpl.java:182)
at android.app.Dialog.dismissDialog(Dialog.java:328)
at android.app.Dialog.dismiss(Dialog.java:311)
at com.example.beerportfoliopro.GetBeerRateJSON.onPostExecute(GetBeerRateJSON.java:74)
at com.example.beerportfoliopro.GetBeerRateJSON.onPostExecute(GetBeerRateJSON.java:27)
at android.os.AsyncTask.finish(AsyncTask.java:631)
at android.os.AsyncTask.access$600(AsyncTask.java:177)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5536)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1074)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:841)
at dalvik.system.NativeStart.main(Native Method)
From the stack trace, it looks like your Dialog isn't visible when the AsyncTask finishes its work. In that case, the call to dismiss() will crash the app.
You might try using Dialog.isShowing() to avoid the crash:
protected void onPostExecute(...) {
...
if (dialog.isShowing()) {
dialog.dismiss(); // or .cancel()
}
...
}
From time to time, I can see logcat messages reporting activity leak. For example:
Activity com.android.internal.app.ChooserActivity has leaked IntentReceiver com.android.internal.app.ResolverActivity$1#4144d6e8 that was originally registered here. Are you missing a call to unregisterReceiver()?
android.app.IntentReceiverLeaked: Activity com.android.internal.app.ChooserActivity has leaked IntentReceiver com.android.internal.app.ResolverActivity$1#4144d6e8 that was originally registered here. Are you missing a call to unregisterReceiver()?
at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:763)
at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:567)
at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1081)
at android.app.ContextImpl.registerReceiver(ContextImpl.java:1068)
at android.app.ContextImpl.registerReceiver(ContextImpl.java:1062)
at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:341)
at com.android.internal.content.PackageMonitor.register(PackageMonitor.java:65)
at com.android.internal.app.ResolverActivity.onCreate(ResolverActivity.java:99)
at com.android.internal.app.ChooserActivity.onCreate(ChooserActivity.java:53)
at android.app.Activity.performCreate(Activity.java:4465)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2033)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
at android.app.ActivityThread.access$600(ActivityThread.java:132)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1157)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4575)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
at dalvik.system.NativeStart.main(Native Method)
My question is: how is this activity leak detected?
To detect memory leak in code, you need to install Memory Analyzer Tool plugin for eclipse.
To understand how to use MAT, please see the following link: http://android-developers.blogspot.in/2011/03/memory-analysis-for-android.html
This is a very useful plugin, though a bit difficult to understand at first go but as you will use it, you will detect the memory leak in no time.
If you face any difficulty, please ask me anytime.
Thank you :)
guys I've been searching and studying about this for a whole day. The app crashes not only when a dialog is open, but also when a spinner is open (and I'm sure it would be bunch of other scenarios that I haven't come across).
choosing between onRetainNonConfigurationInstance() and onConfigurationChanged(Configuration newConfig) won't help me. (maybe I'm wrong) - actually I prefer to use first one.
BUT I want to ask: for a single open dialog box or open spinner do I have to create everything from scratch? is this a way? sometimes it's worthless to reinitialize a big class with lot of widgets inside just for a time that maybe user changes the orientation.
plz give me hints and guidance.
Thanks in advance.
Edited :::
Error code:
01-25 17:56:48.182: ERROR/WindowManager(312): Activity XXX has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#43e63058 that was originally added here
01-25 17:56:48.182: ERROR/WindowManager(312): android.view.WindowLeaked: Activity XXX has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#43e63058 that
was originally added here
01-25 17:56:48.182: ERROR/WindowManager(312): at android.view.ViewRoot.<init>(ViewRoot.java:247)
01-25 17:56:48.182: ERROR/WindowManager(312): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
01-25 17:56:48.182: ERROR/WindowManager(312): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
01-25 17:56:48.182: ERROR/WindowManager(312): at android.view.Window$LocalWindowManager.addView(Window.java:424)
01-25 17:56:48.182: ERROR/WindowManager(312): at android.app.Dialog.show(Dialog.java:241)
01-25 17:56:48.182: ERROR/WindowManager(312): at XXX.menuGroupDialog(XXX.java:946)
0 1-25 17:56:48.182: ERROR/WindowManager(312): at XXX.onOptionsItemSelected
(GroupManagement.java:257)
01-25 17:56:48.182: ERROR/WindowManager(312): at android.app.Activity.onMenuItemSelected(Activity.java:2195)01-25 17:56:48.182: ERROR/WindowManager(312): at
com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:730)
01-25 17:56:48.182: ERROR/WindowManager(312): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:143)
01-25 17:56:48.182: ERROR/WindowManager(312): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:855)
01-25 17:56:48.182:
ERROR/WindowManager(312): at com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:532)
01-25 17:56:48.182: ERROR/WindowManager(312): at com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:122)
01-25 17:56:48.182: ERROR/WindowManager(312): at android.view.View$PerformClick.run(View.java:8816)
01-25 17:56:48.182: ERROR/WindowManager(312): at
android.os.Handler.handleCallback(Handler.java:587)
01-25 17:56:48.182: ERROR/WindowManager(312): at android.os.Handler.dispatchMessage(Handler.java:92)
01-25 17:56:48.182: ERROR/WindowManager(312): at android.os.Looper.loop(Looper.java:123)
01-25 17:56:48.182: ERROR/WindowManager(312): at
android.app.ActivityThread.main(ActivityThread.java:4627)
01-25 17:56:48.182: ERROR/WindowManager(312): at java.lang.reflect.Method.invokeNative(Native Method)
01-25 17:56:48.182: ERROR/WindowManager(312): at java.lang.reflect.Method.invoke(Method.java:521)
01-25 17:56:48.182: ERROR/WindowManager(312): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-25 17:56:48.182: ERROR/WindowManager(312): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-25 17:56:48.182: ERROR/WindowManager(312): at
dalvik.system.NativeStart.main(Native Method)
I know that this is from calling dismiss() function. but how can I handle orientation change when having dialog open?
Are you using progressDialog.show() and progressbarDialog.dismiss() in the AyncTask?
If yes try using showDialog(id) and dismissDialog(id) in the AyncTask instead of it. You will have to write custom dialog in the onCreateDialog() for showing the loading dialog.
showDialog and dismissDialog methods are activity level methods. I mean they are invoked on the Activity or its Context. So even if the activity is recreated after orientation change, latest context will be made available for the Dialog.
check for Sample code here. Modify DIALOG_PROGRESS case in it as per your requirement.
Also, onRetainNonConfigurationInstance() works perfectly with the orientation change. It just that due to window leak problem you are not able to see it.
By default your Activity is destroyed and recreated when the orientation changes. You can turn this off, and handing this configuration change on your own by setting the configChanges attribute.
You can either disable configuration changes, that is to say, you can stop the application from trying to redraw once the orientation of the phone changes by using XML in your Manifest file:
<activity android:name=".Main"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden">
When the orientation of your phone changes, by default Android will try and re-instantiate your page.
I had very similar issue, i resolve it with little change in manifest acitivity attr.
From: android:configChanges="orientation"
To: android:configChanges="keyboardHidden|orientation"
see here : Spinner drop-down list and screen orientation change problem