Sometimes after the card is captured the app will crash.
java.lang.OutOfMemoryError
at android.graphics.Bitmap.nativeCreate(Bitmap.java)
at android.graphics.Bitmap.createBitmap(Bitmap.java:924)
at android.graphics.Bitmap.createBitmap(Bitmap.java:901)
at android.graphics.Bitmap.createBitmap(Bitmap.java:868)
at io.card.payment.ah.a()
at io.card.payment.CardIOActivity.a()
at io.card.payment.CardScanner.onPreviewFrame()
at android.hardware.Camera$EventHandler.handleMessage(Camera.java:1016)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5579)
at java.lang.reflect.Method.invokeNative(Method.java)
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(NativeStart.java)
It happens every time i capture on the Galaxy S5.
Here are the parameters which I'm using to start scan intent:
Intent scanIntent = new Intent(CardInfoActivity.this, CardIOActivity.class);
scanIntent.putExtra(CardIOActivity.EXTRA_APP_TOKEN, Constants.CARD_IO_TOKEN);
scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_CVV, true);
scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_EXPIRY, true);
scanIntent.putExtra(CardIOActivity.EXTRA_SUPPRESS_CONFIRMATION, true);
scanIntent.putExtra(CardIOActivity.EXTRA_SUPPRESS_MANUAL_ENTRY, true);
startActivityForResult(scanIntent, MY_SCAN_REQUEST_CODE);
Maybe anyone knows how to solve this problem?
Android bitmaps keep the image in native memory, not on the Java heap. If you allocate a bunch of images quickly this can happen, since cleanup only happens when the Java GC runs, which is tied to the Java heap. Ensuring you call bitmap.recycle() when you're done with images you've been working with can help.
Related
We call from Ionic a custom Cordova plugin which uses the Camera2 API to capture a frame. On the second call of this plugin within Ionic (which follows subsequently) we get sometimes (like in one out of ten cases) the following error:
2019-01-14 18:08:16.471 31738-31738/io.ionic.starter E/Legacy-CameraDevice-JNI: getNativeWindow: Surface had no valid native window.
2019-01-14 18:08:16.472 31738-31738/io.ionic.starter E/Legacy-CameraDevice-JNI: LegacyCameraDevice_nativeDetectSurfaceDimens: Could not retrieve native window from surface.
2019-01-14 18:08:16.472 31738-31738/io.ionic.starter D/AndroidRuntime: Shutting down VM
2019-01-14 18:08:16.472 31738-31738/io.ionic.starter E/AndroidRuntime: FATAL EXCEPTION: main
Process: io.ionic.starter, PID: 31738
java.lang.UnsupportedOperationException: Unknown error -22
at android.hardware.camera2.legacy.LegacyExceptionUtils.throwOnError(LegacyExceptionUtils.java:77)
at android.hardware.camera2.legacy.LegacyCameraDevice.getSurfaceSize(LegacyCameraDevice.java:583)
at android.hardware.camera2.utils.SurfaceUtils.getSurfaceSize(SurfaceUtils.java:68)
at android.hardware.camera2.params.OutputConfiguration.<init>(OutputConfiguration.java:237)
at android.hardware.camera2.params.OutputConfiguration.<init>(OutputConfiguration.java:101)
at android.hardware.camera2.impl.CameraDeviceImpl.createCaptureSession(CameraDeviceImpl.java:499)
at dev.capture.Camera2Scanner.createCameraPreviewSession(Camera2Scanner.java:675)
at dev.capture.Camera2Scanner.access$200(Camera2Scanner.java:47)
at dev.capture.Camera2Scanner$2.onOpened(Camera2Scanner.java:191)
at android.hardware.camera2.impl.CameraDeviceImpl$1.run(CameraDeviceImpl.java:139)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
So I checked the Android JNI sources for this error, there it says that this error is thrown when getNativeWindow() returns null. But what extactly does this function do and what does this mean for our surface?
You've passed in a Surface to CameraDevice.createCaptureSession that's no longer valid; generally that's because whatever you got the Surface from has been either garbage collected, or because the UI element it draws to is no longer valid.
So if a SurfaceView is not valid to draw to any more, or an ImageReader has been released, etc, you can get this error. You need to sort out which Surface is invalid, and then figure out why its source is no longer in good shape.
I get the following out of memory error and I'm not sure why.
Failed to allocate a 1860508 byte allocation with 905740 free bytes and 884KB until OOM
java.lang.OutOfMemoryError: Failed to allocate a 1860508 byte allocation with 905740 free bytes and 884KB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:837)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:656)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1037)
at android.content.res.Resources.loadDrawableForCookie(Resources.java:4056)
at android.content.res.Resources.loadDrawable(Resources.java:3929)
at android.content.res.Resources.getDrawable(Resources.java:1991)
at android.content.res.Resources.getDrawable(Resources.java:1973)
at android.graphics.drawable.LevelListDrawable.inflate(LevelListDrawable.java:128)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1192)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1086)
at android.content.res.Resources.loadDrawableForCookie(Resources.java:4045)
at android.content.res.Resources.loadDrawable(Resources.java:3929)
at android.content.res.Resources.getDrawable(Resources.java:1991)
at android.content.res.Resources.getDrawable(Resources.java:1973)
at android.content.Context.getDrawable(Context.java:409)
at com.MyCompany.MyApp.Login.updateWifiStatus(Login.java:942)
at com.MyCompany.MyApp.Login$6.run(Login.java:576)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6939)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
I am using a 5 level resource to indicate wifi status and here is the code I'm using
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
// Level of current connection
int rssi = wifiManager.getConnectionInfo().getRssi();
int level = WifiManager.calculateSignalLevel(rssi, 5);
Drawable db = getDrawable(R.drawable.stat_sys_wifi_signal);
db.setLevel(level);
wifiMenu.setIcon(db);
The images are all the same size (512x512).
In reference to other answers out there I have got largeheap in my manifest.
Any help would be greatly appreciated.
Use TinyPNG
TinyPNG uses smart lossy compression techniques to reduce the file
size of your PNG files. By selectively decreasing the number of colors
in the image, fewer bytes are required to store the data. The effect
is nearly invisible but it makes a very large difference in file size!
Compress all images using this link.
Reduce the size of all picture before use in your Android applications.
Make sure you read the document Loading Large Bitmaps Efficiently given by #mudit_sen.
Hope this may help you.
I am trying to display 4 long pieces of text (about 250 chars long each) inside a TextView separated by a few images on android. This is inside a fragment which is placed in a scrollView on the Host activity to make it scrollable.
But it throws
java.lang.OutOfMemoryError
I was surprised to see that the app went out of memory by this because the only thing it has to do is display 250 characters and apply word wrap to it. So after googling it I set android:largeHeap to true to see what would happen. The application does load the text but it uses a lot of CPU resources and makes the UI come to a snail phase.
So I am wondering: what I am doing wrong here?
Thanks for reading.
Here is the complete crash:
java.lang.OutOfMemoryError: Failed to allocate a 69120012 byte
allocation with 8388608 free bytes and 10MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609)
at
android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
at
android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1080)
at
android.content.res.Resources.loadDrawableForCookie(Resources.java:2730)
at android.content.res.Resources.loadDrawable(Resources.java:2635)
at android.content.res.TypedArray.getDrawable(TypedArray.java:870)
at android.widget.ImageView.(ImageView.java:152)
at android.widget.ImageView.(ImageView.java:140)
at
android.support.v7.widget.AppCompatImageView.(AppCompatImageView.java:57)
at
android.support.v7.widget.AppCompatImageView.(AppCompatImageView.java:53)
at
android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106)
at
android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:980)
at
android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:1039)
at
android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
at
android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:189)
at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:746)
at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at
android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at
nl.evhb.evhbmijnopbrengst.FragmentCoTwoInformation.onCreateView(FragmentCoTwoInformation.java:25)
at
android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)
at
android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
at
android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)
at
android.support.v4.app.BackStackRecord.run(BackStackRecord.java:742)
at
android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
at
android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:517)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5461)
at java.lang.reflect.Method.invoke(Native Method)
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
I am sorry but after looking into the log again I realized that I imported the images on full 1080p resolution which is too much to process for android.graphics.BitmapFactory and that is why it goes out of memory.
I made the images to a mobile friendly size and it worked fine.
OutOfMemoryErrorenter code here error is thrown by the Java Virtual Machine (JVM) when an object cannot be allocated due to lack of memory space and also, the garbage collector cannot free some space.
Try it...
<application
.......................
............
android:largeHeap="true"
>
Overview:
I have a fragment-based app with a single activity. On launch, I add my main fragment and all works well. When I tap on something, I call replace() to swap out to the new fragment and add the transaction to the back stack.
Problem:
When the app dies in the background (or most easily repro'd with 'Don't Keep Activities'), and I relaunch the app from the home screen, I get the exception below.
Scenario:
1. Open app
2. Navigate to a secondary fragment (this problem doesn't occur if you never leave the main fragment)
3. Background the app
4. Let the app die naturally (~24hr), or enable 'Don't Keep Activites' in the Developer Options
5. Open app from home screen
Expected:
App opens to main fragment (regardless of what fragment was displayed when backgrounded)
Actual:
Crash below
Other Requirements:
- Background app and immediately tap from home screen must return to previous fragment (assuming it wasn't destroyed in the background).
Stack Trace (note absolutely no calls from my app itself, so nowhere for me to debug):
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.rcg.socialstitch/com.rcg.socialstitch.ViewStitchActivity}: java.lang.IllegalStateException: Fragment already added: ViewStitchFragment{42800520 #1 id=0x7f040030}
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2227)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2276)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5146)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:611)
at dalvik.system.NativeStart.main(NativeStart.java)
Caused by: java.lang.IllegalStateException: Fragment already added: ViewStitchFragment{42800520 #1 id=0x7f040030}
at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1133)
at android.app.BackStackRecord.run(BackStackRecord.java:618)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1447)
at android.app.Activity.performStart(Activity.java:5320)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2190)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2276)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5146)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:611)
at dalvik.system.NativeStart.main(NativeStart.java)
I believe I have solved this. My .replace() calls all added to the back stack, but my initial .add() did not. When I ensured my initial fragment addition was no the back stack, this no longer seems to happen.
I am using crashlytics to track my app's crash. There is one bug which is quite hard to figure out. The stack trace from crashlytics is as below:
java.lang.RuntimeException: Could not read input channel file descriptors from parcel.
at android.view.InputChannel.nativeReadFromParcel(InputChannel.java)
at android.view.InputChannel.readFromParcel(InputChannel.java:148)
at android.view.InputChannel$1.createFromParcel(InputChannel.java:39)
at android.view.InputChannel$1.createFromParcel(InputChannel.java:36)
at com.android.internal.view.InputBindResult.<init>(InputBindResult.java:62)
at com.android.internal.view.InputBindResult$1.createFromParcel(InputBindResult.java:102)
at com.android.internal.view.InputBindResult$1.createFromParcel(InputBindResult.java:99)
at com.android.internal.view.IInputMethodManager$Stub$Proxy.windowGainedFocus(IInputMethodManager.java:851)
at android.view.inputmethod.InputMethodManager.startInputInner(InputMethodManager.java:1292)
at android.view.inputmethod.InputMethodManager.onWindowFocus(InputMethodManager.java:1518)
at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3550)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5293)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(NativeStart.java)
I know there is one similar question about this here. But there is a bit different. And as statistics from crashlytics, the crash happens mainly in SAMSUNG android phone.
I am new to android and don't know why the crash happened and how to fix this kind of crash.
Any suggestion would be much appreciated.
Think it's a very wide area and there could be a lot of situations which can trigger this system level exception. But maybe this example of how it was fixed in a particular project can help someone.
I experienced a similar exception:
"Could not read input channel file descriptors from parcel" on Samsung phone:
java.lang.RuntimeException: Could not read input channel file descriptors from parcel.
at android.view.InputChannel.nativeReadFromParcel(Native Method)
at android.view.InputChannel.readFromParcel(InputChannel.java:148)
at android.view.IWindowSession$Stub$Proxy.addToDisplay(IWindowSession.java:690)
at android.view.ViewRootImpl.setView(ViewRootImpl.java:525)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:269)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
at android.widget.Toast$TN.handleShow(Toast.java:402)
at android.widget.Toast$TN$1.run(Toast.java:310)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
It happened in a big old project which I got for maintenance and this floating bug occurred only after several hours. I spent quite some time on it and also read some related answers on SO regarding it and had no clue except it's a system level bug of Android, and there should be some extra data or duplicates of objects or big objects in memory etc:
https://code.google.com/p/android/issues/detail?id=32470
The last thing I could think about was SoundPool. It's not used a lot in the project - there are not more than 10 different sounds played from time to time. But it was the root cause! Sometimes there were floating exceptions from SoundPool "unable to load sample (null)". And it helped to realize that SoundPool was used in a wrong way:
public void play(int rscId) {
...
final int soundId = soundPool.load(mContext, rscId, 1);
...
soundPool.play(soundId, volume, volume, 5, 0, 1f);
So new id was generated and sound resource was reloaded each time application called play sound method! And after certain amount of time some non related exceptions started to occur until application crashed with the "Could not read input channel file descriptors from parcel" exception.
It's interesting that one of those non related exceptions was: "ExceptionHandled in unable to open database file (code 14)":
ExceptionHandled in unable to open database file (code 14)
android.database.sqlite.SQLiteCantOpenDatabaseException:
unable to open database file (code 14)
at android.database.sqlite.SQLiteConnection.nativeExecuteForCursorWindow
(Native Method)
at android.database.sqlite.SQLiteConnection.executeForCursorWindow
(SQLiteConnection.java:845)
And of course it has nothing to do neither with database nor with toasts/parcels. The fix for that particular situation was very easy: just preload all sounds as it's suggested in Android documentation:
http://developer.android.com/reference/android/media/SoundPool.html
"The loading logic iterates through the list of sounds calling the appropriate SoundPool.load() function. This should typically be done early in the process to allow time for decompressing the audio to raw PCM format before they are needed for playback.
Once the sounds are loaded and play has started, the application can trigger sounds by calling SoundPool.play()."
So I moved soundPool.load() out from play() method and the exception :
"Could not read input channel file descriptors from parcel" has gone as well as the exception "unable to open database file (code 14)".
public void play(int soundId) {
...
soundPool.play(soundId, volume, volume, 5, 0, 1f);
And soundPool.release(); soundPool = null should be called as well when it's not needed anymore. And maybe it also can have an effect on such exceptions, see details here
Could not read input channel file descriptors from parcel
Most probably it's not the exact situation for the original question but hope it can give some information to dig further. I.e. looking for some additional exceptions, swallowed exceptions, or wrong files/data handling.
I am looking for the answer for a long time such as the others facing at this exception.
As I see it, this crash can also be triggered by the unexceptional TextView or EditText which works with the InputMethodManager:
java.lang.RuntimeException: Could not read input channel file descriptors from parcel.
at android.view.InputChannel.nativeReadFromParcel(Native Method)
at android.view.InputChannel.readFromParcel(InputChannel.java:148)
at android.view.InputChannel$1.createFromParcel(InputChannel.java:39)
at android.view.InputChannel$1.createFromParcel(InputChannel.java:36)
at com.android.internal.view.InputBindResult.<init>(InputBindResult.java:68)
at com.android.internal.view.InputBindResult$1.createFromParcel(InputBindResult.java:112)
at com.android.internal.view.InputBindResult$1.createFromParcel(InputBindResult.java:109)
at com.android.internal.view.IInputMethodManager$Stub$Proxy.startInput(IInputMethodManager.java:697)
at android.view.inputmethod.InputMethodManager.startInputInner(InputMethodManager.java:1407)
at android.view.inputmethod.InputMethodManager.checkFocus(InputMethodManager.java:1518)
at android.view.inputmethod.InputMethodManager.restartInput(InputMethodManager.java:1286)
at android.widget.TextView.setText(TextView.java:4718)
at android.widget.TextView.setText(TextView.java:4656)
at android.widget.TextView.append(TextView.java:4330)
at android.widget.TextView.append(TextView.java:4320)
...
When TextView appending text, it will make text to Editable, and start InputMethodManager. But at this time, something goes wrong in the InputMethod process, and it leads to fail to create InputBindResult which reading error from the parcel.
In this case, the workaround is very simple: DO NOT call append on textview directly, use StringBuilder or SpannableStringBuilder to build text and call TextView.setText(text) instead!
Previous users have commented that this can be a hard bug to track down. I caused this by building a custom alert dialog (containing multiple TextView objects) inside of a while loop vice an if statement. The application crashed before displaying the dialog box(es).
I have meet this problem recently.
java.lang.RuntimeException: Could not read input channel file descr
iptors from parcel.
I search the log find following info:
01-01 09:07:52.164 5162 6777 W zygote64: ashmem_create_region failed
for 'indirect ref table': Too many open files
The problem is that I create HandlerThread repeatedly, but don't do it's quit() method, at last result in fd leaked.
ViewRootImpl$ViewRootHandler means you have view.post or view.postDelay.
and in the post method maybe requestFocus or Keyboard