Displayed resolution density of drawables halving on each program start - android

I've got an Android app that uses both drawables from its own resources folder and from the resources folder of a package linked via shared user id.
I'm facing a decrease of the drawables' pixel density (resulting in interpolation artefacts) of only own resources** each time the app is run, while those linked*** appear normal.
Executing the app about the 10th time, it crashes*.
Then loading for the 1st time displays all images in their original density.
The app is based on SDK version 1.6 and no specific density dependent resources, meaning strictly designed for 320 x 480px.
The issue does appear neither on a device with a display size matching as above, nor in an emulator with both matching and larger display size. In the last case the images are correctly scaled to fit.
I don't know where (in the code) to start looking for the reasons of that bug.
Thanks in advance for any hints!
EDIT:
I should also mention that several Dialogs (e.g. ProgressDialog) are drawn in half the size as before when reloading the application.
* Log output when the app crashes:
ERROR/AndroidRuntime(23632): FATAL EXCEPTION: main
ERROR/AndroidRuntime(23632): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp/com.myapp.Paketliste}: android.view.InflateException: Binary XML file line #20: Error inflating class <unknown>
ERROR/AndroidRuntime(23632): Caused by: android.view.InflateException: Binary XML file line #20: Error inflating class <unknown>
ERROR/AndroidRuntime(23632): Caused by: java.lang.reflect.InvocationTargetException
ERROR/AndroidRuntime(23632): Caused by: android.content.res.Resources$NotFoundException: File res/drawable/buttons.png from drawable resource ID #0x7f020016
ERROR/AndroidRuntime(23632): Caused by: java.lang.IllegalArgumentException: width and height must be > 0
WARN/ActivityManager(2461): Force finishing activity com.myapp/.Paketliste
* * The image loaded by these lines appears as described above:
ImageView imageView_IconOfAnotherPackage = (ImageView) row
.findViewById(R.id.paketliste_installed);
imageView_IconOfAnotherPackage
.setImageResource(R.drawable.default_icon);
* * * Loading an image which appears WITHOUT AN ISSUE:
imageView_IconOfAnotherPackage
.setImageDrawable(this
.getPackageManager()
.getResourcesForApplication('com.myotherapp')
.getDrawable(0x7f020001)
);

I found a post where a guy presumably was having the same problem (and found a solution) here:
http://adrianvintu.com/blogengine/post/Force-Locale-on-Android.aspx
(via this answer: Set-up the application Language in Android Preferences)

Related

ARCore Image Extraction from GPU

I try to extract image directly from the GPU (so without using AcquireCameraImageBytes()) for performance reason (Samsung S9 can't reach 10fps) and to support the Xiaomi Pocophone I bought. I use the class TextureReader, included inside the ComputerVision example, but OnImageAvailableCallback is never called and log show some error during initialization:
camera_utility: Failed to create OpenGL frame buffer.
camera_utility: Failed to create OpenGL frame buffer.
I insert a couple of breakpoints inside libarcore_camera_utility.so. And I see that glCheckFramebufferStatus inside TextureReader::create return 0 (so a error occurred), but glGetError() don't return any error. How it's possible resolve the problem?

tensorflow TF lite android app crashing after detection

I have trained my model using ssd_mobilenet_v2_quantized_coco, which was also a long painstaking process of digging. Once training was successful, the model was correctly detecting images from my laptop but on my phone as soon as an object is detected, app crashes. I used TF lite Android app available at GitHub. I did some debugging on Android Studio and getting the following error log when an object gets detected and app crashes:
I/tensorflow: MultiBoxTracker: Processing 0 results from 314 I/tensorflow:
DetectorActivity: Preparing image 506 for detection in bg thread.
I/tensorflow: DetectorActivity: Running detection on image 506
I/tensorflow: MultiBoxTracker: Processing 0 results from 506
I/tensorflow: DetectorActivity: Preparing image 676 for detection in bg thread.
I/tensorflow: DetectorActivity: Running detection on image 676
E/AndroidRuntime: FATAL EXCEPTION: inference
Process: org.tensorflow.lite.demo, PID: 3122
java.lang.ArrayIndexOutOfBoundsException: length=80; index=-2147483648
at java.util.Vector.elementData(Vector.java:734)
at java.util.Vector.get(Vector.java:750)
at org.tensorflow.demo.TFLiteObjectDetectionAPIModel.recognizeImage(TFLiteObjectDetectionAPIModel.java:213)
at org.tensorflow.demo.DetectorActivity$3.run(DetectorActivity.java:247)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.os.HandlerThread.run(HandlerThread.java:65)
My guess is labels located in .txt file being somehow misread. This is because of the line:
at org.tensorflow.demo.TFLiteObjectDetectionAPIModel.recognizeImage(TFLiteObjectDetectionAPIModel.java:213)
and that line corresponds to the following code:
labels.get((int) outputClasses[0][i] + labelOffset)
However, I don't know what to change in labels.txt. Possibly, I need to edit that txt as suggested here. Any other suggestions and explanation for possible causes are appreciated.
Update. I added ??? to the labels.txt and compiled/run, but I am still getting the same error as above.
P.S. I trained ssdmobilenet_V2_coco (the model without quantization) as well and it is working without crash on the app. I am guessing, perhaps, quantization is converting label indices differently and maybe resulting in outofbound error for labels.
Yes it is because the output of labels at times gets garbage value. For a quick fix you can try this:
add a condition:
if((int) outputClasses[0][i]>10)
{
outputClasses[0][i]=-1;
}
here 10 is the number of classes for which the model was trained for. You can change it accordingly.

Draw error when moving from desktop to android... android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:474)

I am getting a lot of different errors when trying to make my app work on android, when it works perfectly on my desktop. I've managed most of the errors but this error I cant figure out. I tried removing every drawable texture or animation one by one but still got the same error even with an empty screen.
E/AndroidRuntime: FATAL EXCEPTION: GLThread 96
java.lang.NullPointerException
at java.lang.String.<init>(String.java:443)
at com.jteck.game.states.PlayState.<init>(PlayState.java:118)
at com.jteck.game.states.MenuState.handleInput(MenuState.java:56)
at com.jteck.game.states.MenuState.update(MenuState.java:78)
at com.jteck.game.states.GameStateManager.update(GameStateManager.java:31)
at com.jteck.game.Hangman.render(Hangman.java:36)
at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:474)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1516)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
So, something causes the NullPointerException on the line 118 in the PlayState class.

Android M: Scene transition with hero elements throws java.lang.IllegalStateException

I have a scene transition that I had some issues with:
Scene transition with hero elements throws Layer exceeds max. dimensions supported by the GPU
But setting transitionGroup fixed it. When I compile the exact same app with the the latest Android M SDK it crashes when pressing back from the transition.
Abort message: 'art/runtime/java_vm_ext.cc:410] JNI DETECTED ERROR IN APPLICATION:
JNI CallObjectMethod called with pending exception java.lang.IllegalStateException:
Unable to create layer for RelativeLayout'
Anyone knows if Google changed anything regarding this in Android M?
It is reported here:
https://code.google.com/p/android-developer-preview/issues/detail?id=2416
But no resolution...

Out of Memory Picasso Lib

I'm developing an app that loads a lot of images through lib Picasso. When I'm navigating through the app, suddenly the app crashes, giving out of memory.
I already tried to do somethings to avoid this kind of problem, but with no success.
If someone could help me, i would be glad.
Below the code:
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.codal.whatsee/com.codal.whatsee.fragmentactivity.ItemPostFragmentActivity}: android.view.InflateException: Binary
XML file line #55: Error inflating class <unknown>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2217)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2266)
at android.app.ActivityThread.access$800(ActivityThread.java:145)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1206)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5141)
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:795)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:611)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #55: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:620)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:343)
at android.app.Activity.setContentView(Activity.java:1929)
at com.codal.whatsee.fragmentactivity.ItemPostFragmentActivity.onCreate(ItemPostFragmentActivity.java:150)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2171)
... 11 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:594)
... 23 more
Caused by: java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:594)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:429)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:840)
at android.content.res.Resources.loadDrawable(Resources.java:2208)
at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
at android.widget.ImageView.<init>(ImageView.java:129)
at android.widget.ImageView.<init>(ImageView.java:119)
at com.codal.whatsee.utils.SquareImageView.<init>(SquareImageView.java:13)
... 26 more
OBS: This problem happens not just in this class, but in any other class happens too.
This sounds a lot like your application is leaking memory and the image decoding is just the last operation that fills the heap. You should use the android DDMS tools and create a heap dump of your app after short use. If you see many Activities or Fragments in the dump, you should try to figure out which objects are still holding references to them.
Here is the related page from the developer site:
https://developer.android.com/tools/debugging/debugging-memory.html
You can expect such exception when dealing with images and bitmap. In present case it appears that out of memory is due to loading of a large/big image which consume the available memory and creating issue.
Luckily picasso lib offers an option to scale down your image so that it may not consumed much memory and thus lower down the chances for getting out of memory exception.
See if this below code is helpful to you or not.
Picasso.with(context).load(file).resize(sizeToScaleDown, sizeToSacleDown).onlyScaleDown().into(imageView);
Note: onlyScaleDown() function only works if you have also used resize() function. Using onlyScaleDown() function without resize() function will cause you exception.
Android 4.2 and 4.3 do not free the memory for a bitmap unless you finish the activity using the bitmap or recycle it (Bitmap.recycle()). See Android Bitmap Memory Analysis - Part 3. API Version Comparison for a detailed analysis. In Android 4.3 you need to additionally remove the image view from the view hierarchy.
So if you have an app where you can build up a deep navigation history and are using Picasso, you will run out of memory sooner or later because Picasso does not track references to bitmaps and therefore cannot call Bitmap.recycle() for them.
We had a similar issue and finally switched to Facebook's Fresco library, which goes at great length to track references. It is therefore more complex too use but it pays off.
You may be getting OOM because of the following:
You are doing some operation that continuously demands a lot of memory. Like Picasso Lib fetching large images/bitmaps which plays with bitmap operations
Picasso uses fit() or resize() methods while fetching the images. ReferenceLink
Memory leaks: You didn’t made the previous objects you allocated eligible for Garbage Collection (GC)
Use memory analyzer tool for taking Dump check where object are getting leak.
Dealing with large bitmaps. Scaling and bitmap operation take the memory from the heap.
I came across this link. It may help you : Link

Categories

Resources