VisionSmarts / pic2shop-client

Client apps (iOS and Android) for pic2shop barcode scanner
Other
20 stars 22 forks source link

Crash resulting from sending new intent too quickly? #1

Open Grunthos opened 11 years ago

Grunthos commented 11 years ago

Hi,

I am trying to use pic2shop to scan barcodes from the Book Catalogue app on a Nexus 7.

The code to call the app boils down to:

mIntent = new Intent(Scan.ACTION); // ACTION=com.visionsmarts.pic2shop.SCAN
a.startActivityForResult(mIntent, requestCode);

the onActivityResult code gets the barcode via:

intent.getStringExtra(Scan.BARCODE);

and I perform validation on the barcode; if it is invalid, I restart the Intent (as above).

If the validation fails, and the scanner is restarted, it crashes (crash report sent).

If I am in the debugger, and wait a few seconds before restarting the scanne, it works. If I put a delay of 5 second, it works (1 second is not enough).

It looks like a cleanup/timing error (logs show an NPE).

Any help would be appreciated!

Grunthos commented 11 years ago

FWIW, this does NOT crash on an HTC running android 4.0.3, but it does crash on a Nexus running 4.2.1 (as per crash reports).

Steven-Mark-Ford commented 11 years ago

I found this delay work around also works on the Samsung Galaxy Tab 2 7". stack trace: 04-09 11:35:27.746: E/AndroidRuntime(15761): java.lang.NullPointerException 04-09 11:35:27.746: E/AndroidRuntime(15761): at com.visionsmarts.pic2shop.view.ScannerLiveView.stopCamera(ScannerLiveView.java:353) 04-09 11:35:27.746: E/AndroidRuntime(15761): at com.visionsmarts.pic2shop.view.ScannerLiveView.surfaceDestroyed(ScannerLiveView.java:240) 04-09 11:35:27.746: E/AndroidRuntime(15761): at android.view.SurfaceView.updateWindow(SurfaceView.java:521) 04-09 11:35:27.746: E/AndroidRuntime(15761): at android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:230) 04-09 11:35:27.746: E/AndroidRuntime(15761): at android.view.View.dispatchWindowVisibilityChanged(View.java:5886) 04-09 11:35:27.746: E/AndroidRuntime(15761): at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:947) 04-09 11:35:27.746: E/AndroidRuntime(15761): at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:947) 04-09 11:35:27.746: E/AndroidRuntime(15761): at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:947) 04-09 11:35:27.746: E/AndroidRuntime(15761): at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:947) 04-09 11:35:27.746: E/AndroidRuntime(15761): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1018) 04-09 11:35:27.746: E/AndroidRuntime(15761): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2505) 04-09 11:35:27.746: E/AndroidRuntime(15761): at android.os.Handler.dispatchMessage(Handler.java:99) 04-09 11:35:27.746: E/AndroidRuntime(15761): at android.os.Looper.loop(Looper.java:137) 04-09 11:35:27.746: E/AndroidRuntime(15761): at android.app.ActivityThread.main(ActivityThread.java:4514) 04-09 11:35:27.746: E/AndroidRuntime(15761): at java.lang.reflect.Method.invokeNative(Native Method) 04-09 11:35:27.746: E/AndroidRuntime(15761): at java.lang.reflect.Method.invoke(Method.java:511) 04-09 11:35:27.746: E/AndroidRuntime(15761): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790) 04-09 11:35:27.746: E/AndroidRuntime(15761): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557) 04-09 11:35:27.746: E/AndroidRuntime(15761): at dalvik.system.NativeStart.main(Native Method)

VisionSmarts commented 11 years ago

It may be related to the developer settings "Do not keep activities" that is on by default on some devices. Please try switching it off.

Source: http://stackoverflow.com/a/15626171

Steven-Mark-Ford commented 11 years ago

Yeah I was still getting a crash on the Samsung Galaxy Tab 2 after implementing the delay so I will give this a try and let you know.

Grunthos commented 11 years ago

Was not turned on on the device that crashes; also, the setting is designed to help developers catch bugs in apps, so if turning it on causes crashes, the app probably needs to be fixed.

Specifically, android can dispose of an activity at any time, and the setting ensures it will. So I would guess that if the underlying problem is fixed, my tablet will work.

Steven-Mark-Ford commented 11 years ago

@VisionSmarts I tried the "Do not keep activities" setting and it did not work. It never seems to be the first time the app launches. i.e. if I launch pic 2 shop and capture barcode (for the first time) it works and returns the result correctly too my activity but subsequent calls are less stable and sometimes return null result to my activity before even showing the pic 2 shop application suggesting the pic-2-shop application is in a strange state. However, if I capture a barcode and return the result, then force close pic-2-shop, and repeat, it always works. In the interim to resolving the root cause can you not make an intent flag available to pic-2-shop client developers where we pass in whether or not the pic-2-shop application should kill itself on returning the result?

Thanks in advance