Calling intentIntegrator.initiateScan() causes Android.View.WindowLeaked error

1,015 views
Skip to first unread message

Derek Chadwell

unread,
Apr 19, 2010, 2:55:37 PM4/19/10
to zxing
I've written a program around using the scanner via intents, and for a
long time it used to work great. Now, when I try to start
IntentIntegrator.initiateScan(), I get the error:

ERROR/WindowManager(7901): Activity [my activity that calls
IntentIntegrator] has leaked window
com.android.internal.policy.impl.PhoneWindow$DecorView@43872bc8 that
was originally added here

My web searching has found that people have this problem when dealing
with their alert dialogs, but I've only added one to my program and
commenting it out doesn't solve the problem. Any insight on the
problem here is welcome. Below is the stack trace from the error:





04-19 14:45:35.757: ERROR/WindowManager(7901): Activity
com.snt.estore.StoreCamera has leaked window
com.android.internal.policy.impl.PhoneWindow$DecorView@43872bc8 that
was originally added here
04-19 14:45:35.757: ERROR/WindowManager(7901):
android.view.WindowLeaked: Activity com.snt.estore.StoreCamera has
leaked window com.android.internal.policy.impl.PhoneWindow
$DecorView@43872bc8 that was originally added here
04-19 14:45:35.757: ERROR/WindowManager(7901): at
android.view.ViewRoot.<init>(ViewRoot.java:214)
04-19 14:45:35.757: ERROR/WindowManager(7901): at
android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
04-19 14:45:35.757: ERROR/WindowManager(7901): at
android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
04-19 14:45:35.757: ERROR/WindowManager(7901): at
android.view.Window$LocalWindowManager.addView(Window.java:409)
04-19 14:45:35.757: ERROR/WindowManager(7901): at
android.app.Dialog.show(Dialog.java:238)
04-19 14:45:35.757: ERROR/WindowManager(7901): at
android.app.AlertDialog$Builder.show(AlertDialog.java:802)
04-19 14:45:35.757: ERROR/WindowManager(7901): at
com.snt.estore.IntentIntegrator.showDownloadDialog(IntentIntegrator.java:
156)
04-19 14:45:35.757: ERROR/WindowManager(7901): at
com.snt.estore.IntentIntegrator.initiateScan(IntentIntegrator.java:
133)
04-19 14:45:35.757: ERROR/WindowManager(7901): at
com.snt.estore.StoreCamera.onCreate(StoreCamera.java:27)
04-19 14:45:35.757: ERROR/WindowManager(7901): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:
1123)
04-19 14:45:35.757: ERROR/WindowManager(7901): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2364)
04-19 14:45:35.757: ERROR/WindowManager(7901): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
2417)
04-19 14:45:35.757: ERROR/WindowManager(7901): at
android.app.ActivityThread.access$2100(ActivityThread.java:116)
04-19 14:45:35.757: ERROR/WindowManager(7901): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
04-19 14:45:35.757: ERROR/WindowManager(7901): at
android.os.Handler.dispatchMessage(Handler.java:99)
04-19 14:45:35.757: ERROR/WindowManager(7901): at
android.os.Looper.loop(Looper.java:123)
04-19 14:45:35.757: ERROR/WindowManager(7901): at
android.app.ActivityThread.main(ActivityThread.java:4203)
04-19 14:45:35.757: ERROR/WindowManager(7901): at
java.lang.reflect.Method.invokeNative(Native Method)
04-19 14:45:35.757: ERROR/WindowManager(7901): at
java.lang.reflect.Method.invoke(Method.java:521)
04-19 14:45:35.757: ERROR/WindowManager(7901): at
com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:791)
04-19 14:45:35.757: ERROR/WindowManager(7901): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
04-19 14:45:35.757: ERROR/WindowManager(7901): at
dalvik.system.NativeStart.main(Native Method)

Thanks,

Derek


--
Subscription settings: http://groups.google.com/group/zxing/subscribe?hl=en

Sean Owen

unread,
Apr 19, 2010, 4:47:36 PM4/19/10
to zxing
I haven't heard of this. The integrator does spawn an Alert to prompt
for download.
What's your reference on the issue? we can look at how the issue may
have implications for how the integrator works.

Derek Chadwell

unread,
Apr 20, 2010, 11:37:35 AM4/20/10
to zxing
I'm not sure what you're asking for... Here is my only reference to
Zxing from my own:


public class MyClass extends Activity implements RequestListener{

private Activity temp;
private int FOUND_BARCODE=0;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
temp = this;
IntentIntegrator
.initiateScan(
temp,
"Barcode Scan",
"You must download the barcode scanner utility to access this
function",
"Go to Marketplace", "Cancel");
}

public void onActivityResult(int requestCode, int resultCode, Intent
intent) {
IntentResult scanResult = IntentIntegrator.parseActivityResult(
requestCode, resultCode, intent);
if (scanResult.getContents() != null) {
// handle scan result
//I put a TCP request here on a TCP connection thread manager

ObjectHolder.getConnectionQueue().AddRequest(cr);
}
else{
finish();
}

}

@Override
public void finish() {
if(FOUND_BARCODE == 1){
Intent i = new Intent(this, AClassOfMine.class);
i.putExtra("index", 0);
i.putExtra("parent", Constants.ACONSTANT);
startActivity(i);
}
super.finish();
}

@Override
public void infoEvent(String info) {
System.out.println("********"+info+"***********");

}

@Override
public void responseReceived(byte[] data, int type, int row) {
if (data == null)
return;
//This callback handles the response from the TCP connection, I
//do some stuff with the information, and call finish()
finish();
}
}


Also, I have some more information on how these interactions are
working. My programming partner and I have dev phones, and on mine I
had what I'll refer to as the "old" copy of Zxing (my partner
mentioned that an update had come out for it recently). With the old
copy of Zxing on my phone, the program would crash with the window
leaked error. I tried uninstalling Zxing from my phone to see if
IntentIntegrator would handle downloading it (in the past this has
also worked fine) and the problem would solve itself, but I still ran
into the error. When I downloaded the latest version of my program
onto my partners dev phone, his phone (which has the "new" version of
ZXing) worked as expected with my program. I have not tried
uninstalling ZXing from his phone to see if IntentIntegrator will
correctly handle the download. I have also not yet tried installing
the new ZXing on mine to see if it'll work.

Did a new version of IntentIntegrator and IntentResult come out with
the "new" Zxing?

Sean Owen

unread,
Apr 20, 2010, 4:21:35 PM4/20/10
to zxing
I meant that you referred to "people have this problem when dealing
with their alert dialogs" -- what are you referring to here? I'd like
to see what the issue and solution is, if you've already looked it up,
because the integrator code provided does spawn an Alert.

The integrator code is unrelated to the application. It is code that
goes in your app and spawns an Intent. The app doesn't come into play;
in fact the integrator is mostly there to help in the case that the
app isn't even on the phone. So no I think that must be a red herring.
Message has been deleted

Derek Chadwell

unread,
Apr 20, 2010, 6:44:02 PM4/20/10
to zxing
Oh, I haven't found any good solution yet. I found this today :

http://www.mail-archive.com/android-d...@googlegroups.com/msg05692.html

That mentions that you need to dismiss the alert dialog when onPause
is created? I'll give it a shot later

PS - the phone it was working on broke when I uninstalled the scanner,
so you were right.

Sean Owen

unread,
Apr 20, 2010, 8:25:45 PM4/20/10
to zxing
I see. So it's not causing much trouble in practice beyond this, but
it would be nice if the app had some chance to properly clean up. I
can change the code to return the AlertDialog to you after you
initiateScan() so you can manage it, at least, per this thread. Watch
for an update in SVN in a bit.

Derek Chadwell

unread,
Apr 23, 2010, 11:27:41 AM4/23/10
to zxing
Any progress on this?

Sean Owen

unread,
Apr 23, 2010, 11:37:55 AM4/23/10
to zxing
Yes, I committed the change a few days ago that lets you get at the
AlertDialog. You can dismiss() it in your onPause() method.

Derek Chadwell

unread,
Apr 26, 2010, 4:55:02 PM4/26/10
to zxing
Hi,

I fell victim to the same mistake twice, like an idiot.
onResultReturned() gets called twice during the instantiation of the
barcode scanner when you have to download it, and I had my activity
finish()ing if the scan returned no data (which it inevitably does if
the scanner is not installed). THAT'S what was causing the window
leaked error.

Also, your activity inevitably gets paused when you 1. go to the
marketplace to download the scanner or, 2. open the ZXing program. So
you can safely revert IntentIntegrator.java back to the previous
version without fear of my problem causing someone else any heartache.

Thanks for the help though, and the program rocks.

Derek

Sean Owen

unread,
Apr 26, 2010, 5:22:59 PM4/26/10
to zxing
Cool thanks for the report. I'll leave the change in since it doesn't
really hurt to give people access to that object.
Reply all
Reply to author
Forward
0 new messages