Android GraphicBufferAlloc::createGraphicBuffer(w=1232, h=800) failed (Out of memory) - android

I am restarting the activity after updating some fields through api call, after 10-15 continuous updates it is giving an exception as below :
05-06 17:12:55.412: E/SurfaceFlinger(115): GraphicBufferAlloc::createGraphicBuffer(w=1232, h=800) failed (Out of memory), handle=0x0
05-06 17:12:55.412: E/BufferQueue(115): [com.ht.coremoney/com.ht.coremoney.cards.TransactionFullDetailActivity] dequeueBuffer: SurfaceComposer::createGraphicBuffer failed
05-06 17:12:55.420: E/libEGL(1350): eglMakeCurrent:534 error 3003 (EGL_BAD_ALLOC)
05-06 17:12:55.428: E/ViewRootImpl(1350): OutOfResourcesException initializing HW surface
05-06 17:12:55.428: E/ViewRootImpl(1350): android.view.Surface$OutOfResourcesException: eglMakeCurrent failed EGL_BAD_ALLOC
05-06 17:12:55.428: E/ViewRootImpl(1350): at android.view.HardwareRenderer$GlRenderer.createEglSurface(HardwareRenderer.java:920)
05-06 17:12:55.428: E/ViewRootImpl(1350): at android.view.HardwareRenderer$GlRenderer.initialize(HardwareRenderer.java:748)
05-06 17:12:55.428: E/ViewRootImpl(1350): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1621)
05-06 17:12:55.428: E/ViewRootImpl(1350): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)
05-06 17:12:55.428: E/ViewRootImpl(1350): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4464)
05-06 17:12:55.428: E/ViewRootImpl(1350): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
05-06 17:12:55.428: E/ViewRootImpl(1350): at android.view.Choreographer.doCallbacks(Choreographer.java:555)
05-06 17:12:55.428: E/ViewRootImpl(1350): at android.view.Choreographer.doFrame(Choreographer.java:525)
05-06 17:12:55.428: E/ViewRootImpl(1350): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
05-06 17:12:55.428: E/ViewRootImpl(1350): at android.os.Handler.handleCallback(Handler.java:615)
05-06 17:12:55.428: E/ViewRootImpl(1350): at android.os.Handler.dispatchMessage(Handler.java:92)
05-06 17:12:55.428: E/ViewRootImpl(1350): at android.os.Looper.loop(Looper.java:137)
05-06 17:12:55.428: E/ViewRootImpl(1350): at android.app.ActivityThread.main(ActivityThread.java:4895)
05-06 17:12:55.428: E/ViewRootImpl(1350): at java.lang.reflect.Method.invokeNative(Native Method)
05-06 17:12:55.428: E/ViewRootImpl(1350): at java.lang.reflect.Method.invoke(Method.java:511)
05-06 17:12:55.428: E/ViewRootImpl(1350): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
05-06 17:12:55.428: E/ViewRootImpl(1350): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
05-06 17:12:55.428: E/ViewRootImpl(1350): at dalvik.system.NativeStart.main(Native Method)
05-06 17:12:55.428: E/android.os.Debug(1350): !#Dumpstate > dumpstate -k -t -z -d -o /data/log/dumpstate_surfaceoom
Kindly suggest me the solution.

Let's analyse what this says:
GraphicBufferAlloc::createGraphicBuffer(w=1232, h=800) failed (Out of memory)
You seem to allocate a native buffer, 985600 pixels. If they use a 32-bit color format, that's 3.94 MB of memory. Taking into account that you do this 10 to 15 times, you allocate up to 59.14 MB of memory, far too much for most devices.
My guess is that you forgot to actually free these buffers, therefore wasting lots of memory.
When using native code, your memory is only freed when your process is killed, not when the activity is restarted. Therefore, your code allocates a new buffer every time the activity is started. You should either free when the activity closes or reuse the already allocated buffer.

Let's understand Exception and Error in java.
In your situation you got an error by doing something wrong you can't handle or manage It like exception,
That's mean you need to analyze you memory management of your Application..
By the using the eclipse Memory Analyzer tools.
It's plugged in already with Android ADT.
Here are link for using memory
Analyzer.
http://www.vogella.com/tutorials/EclipseMemoryAnalyzer/article.html
http://android-developers.blogspot.in/2011/03/memory-analysis-for-android.html?m=1
I know it's not your direct solution but with the help of this tool you can analyze your all memory leakage and try to reuse your preallocated buffer ,
And android is also recommend that's do not use very complex layouting in a or heavy nested layouting in single layout, instead of all this you can break up all complex layout into sm fragments.
Hope this information help you.

Related

Android internal NPE in ViewGroup dispatchAttachedToWindow

Does anyone knows how to solve the following bug ?
java.lang.NullPointerException
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2434)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2434)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2434)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2434)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2434)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1313)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1110)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4484)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
at android.view.Choreographer.doCallbacks(Choreographer.java:555)
at android.view.Choreographer.doFrame(Choreographer.java:525)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4856)
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:1007)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
at dalvik.system.NativeStart.main(NativeStart.java)
I got it a few times on Android 4.1 devices when the app is coming back from the background.
You get this only on 4.1v?
Seems that your rootview or your windows is unavailable, we need more coder/log info to get better results.
If so, there isn't a bug, you need to check for your views not null, maybe the GC has quit your view so you get this error.
Please tell us more info, when happens, frequently?, how many time has pass from background?, and so on

Android HDR scene mode

I'm trying to implement an app that take photos using HDR mode.
My phone is an Galaxy S3 and in the native camera, I have the option to enable HDR.
However, I'm getting an exception when setting it in the app.
I set the HDR like this:
params.setSceneMode("hdr");
Then, when I try to set the params back:
mCamera.setParameters(params);
I get this exception:
java.lang.RuntimeException: setParameters failed
at android.hardware.Camera.native_setParameters(Native Method)
at android.hardware.Camera.setParameters(Camera.java:1606)
at com.myapp.Preview.surfaceCreated(Preview.java:131)
at android.view.SurfaceView.updateWindow(SurfaceView.java:610)
at android.view.SurfaceView.access$000(SurfaceView.java:93)
at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:182)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:864)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2142)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1249)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6364)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:791)
at android.view.Choreographer.doCallbacks(Choreographer.java:591)
at android.view.Choreographer.doFrame(Choreographer.java:561)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:777)
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:5419)
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:1046)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
at dalvik.system.NativeStart.main(Native Method)
Any help? What am I doing wrong?
I have also tried to use the constant:
params.setSceneMode(Parameters.SCENE_MODE_HDR);
Same error.
Thanks!

How can use not embedded fonts for create new pdf file using itext in android

I am using iText library for generate new pdf in my app. but my question is how can i use not embedded fonts in program? I'll try this code but its not working for me.
FONTS = "assets/Zapfino.ttf"
BaseFont bf = BaseFont.createFont(FONTS,"CP1251", BaseFont.EMBEDDED);
font = new Font(bf,18);
Paragraph pr = new Paragraph(p12,font);
document.add(pr);
and giv error this
05-06 10:08:31.740: W/System.err(1129): com.itextpdf.text.DocumentException: assets/Zapfino.ttf cannot be embedded due to licensing restrictions.
05-06 10:08:31.740: W/System.err(1129): at com.itextpdf.text.pdf.TrueTypeFont.<init>(TrueTypeFont.java:371)
05-06 10:08:31.740: W/System.err(1129): at com.itextpdf.text.pdf.BaseFont.createFont(BaseFont.java:699)
05-06 10:08:31.740: W/System.err(1129): at com.itextpdf.text.pdf.BaseFont.createFont(BaseFont.java:615)
05-06 10:08:31.740: W/System.err(1129): at com.itextpdf.text.pdf.BaseFont.createFont(BaseFont.java:450)
05-06 10:08:31.740: W/System.err(1129): at com.example.pdfformate.MainActivity.createPdf(MainActivity.java:108)
05-06 10:08:31.740: W/System.err(1129): at com.example.pdfformate.MainActivity.access$0(MainActivity.java:90)
05-06 10:08:31.750: W/System.err(1129): at com.example.pdfformate.MainActivity$1.onClick(MainActivity.java:74)
05-06 10:08:31.750: W/System.err(1129): at android.view.View.performClick(View.java:2485)
05-06 10:08:31.750: W/System.err(1129): at android.view.View$PerformClick.run(View.java:9080)
05-06 10:08:31.750: W/System.err(1129): at android.os.Handler.handleCallback(Handler.java:587)
05-06 10:08:31.750: W/System.err(1129): at android.os.Handler.dispatchMessage(Handler.java:92)
05-06 10:08:31.750: W/System.err(1129): at android.os.Looper.loop(Looper.java:123)
05-06 10:08:31.750: W/System.err(1129): at android.app.ActivityThread.main(ActivityThread.java:3683)
05-06 10:08:31.750: W/System.err(1129): at java.lang.reflect.Method.invokeNative(Native Method)
05-06 10:08:31.750: W/System.err(1129): at java.lang.reflect.Method.invoke(Method.java:507)
05-06 10:08:31.750: W/System.err(1129): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-06 10:08:31.750: W/System.err(1129): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-06 10:08:31.750: W/System.err(1129): at dalvik.system.NativeStart.main(Native Method)
Any help?

Android: can't replace one fragment with another

I need to replace a Fragment in one Activity with another Fragment, below is the layer file of the Activity:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/home_layout_container">
<fragment android:name="com.foo.FragA"
android:id="#+id/home_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</FrameLayout>
so by default there is FragA, now I want to replace it with FragB in activity, I did:
public void onRegionClicked(Region region) {
RegionInfoFragment rif = RegionInfoFragment.newInstance(region);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.home_list, rif);
}
But I got exception:
>6:24:40.685: ERROR/AndroidRuntime(9194): Uncaught handler: thread main exiting due to uncaught exception
05-06 16:24:40.692: ERROR/AndroidRuntime(9194): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
05-06 16:24:40.692: ERROR/AndroidRuntime(9194): at android.view.ViewGroup.addViewInner(ViewGroup.java:1857)
05-06 16:24:40.692: ERROR/AndroidRuntime(9194): at android.view.ViewGroup.addView(ViewGroup.java:1752)
05-06 16:24:40.692: ERROR/AndroidRuntime(9194): at android.view.ViewGroup.addView(ViewGroup.java:1709)
05-06 16:24:40.692: ERROR/AndroidRuntime(9194): at android.view.ViewGroup.addView(ViewGroup.java:1689)
05-06 16:24:40.692: ERROR/AndroidRuntime(9194): at android.support.v4.app.NoSaveStateFrameLayout.wrap(NoSaveStateFrameLayout.java:40)
05-06 16:24:40.692: ERROR/AndroidRuntime(9194): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:743)
05-06 16:24:40.692: ERROR/AndroidRuntime(9194): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:933)
05-06 16:24:40.692: ERROR/AndroidRuntime(9194): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:578)
05-06 16:24:40.692: ERROR/AndroidRuntime(9194): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1219)
05-06 16:24:40.692: ERROR/AndroidRuntime(9194): at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:380)
05-06 16:24:40.692: ERROR/AndroidRuntime(9194): at android.os.Handler.handleCallback(Handler.java:587)
05-06 16:24:40.692: ERROR/AndroidRuntime(9194): at android.os.Handler.dispatchMessage(Handler.java:92)
05-06 16:24:40.692: ERROR/AndroidRuntime(9194): at android.os.Looper.loop(Looper.java:123)
05-06 16:24:40.692: ERROR/AndroidRuntime(9194): at android.app.ActivityThread.main(ActivityThread.java:4363)
05-06 16:24:40.692: ERROR/AndroidRuntime(9194): at java.lang.reflect.Method.invokeNative(Native Method)
05-06 16:24:40.692: ERROR/AndroidRuntime(9194): at java.lang.reflect.Method.invoke(Method.java:521)
05-06 16:24:40.692: ERROR/AndroidRuntime(9194): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
05-06 16:24:40.692: ERROR/AndroidRuntime(9194): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
05-06 16:24:40.692: ERROR/AndroidRuntime(9194): at dalvik.system.NativeStart.main(Native Method)
What can I do?
Thanks!
You cannot replace a fragment defined statically in the layout file. You can only replace fragments that you added dynamically via a FragmentTransaction.
Try to commit() at the end of the ft, you need to commit() your changes to let it know.
getFragmentManger()
.beginTransaction
.replace(R.id.frame,Yourfragment.newInstance(),null)
.addtobackstack
.commit();
People always say I am one-liner, so here is one-liner solution for you

java.lang.OutOfMemoryError bitmap create?

I just got this stack trace from the marketplace error reporting and have no idea where to being to track the problem down, any help appreciated.
java.lang.OutOfMemoryError: bitmap size exceeds VM budget
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:477)
at android.graphics.Bitmap.createBitmap(Bitmap.java:444)
at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:349)
at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:488)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:463)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:326)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
at android.content.res.Resources.loadDrawable(Resources.java:1709)
at android.content.res.Resources.getDrawable(Resources.java:581)
at com.android.internal.view.menu.MenuItemImpl.getIcon(MenuItemImpl.java:440)
at com.android.internal.view.menu.IconMenuItemView.initialize(IconMenuItemView.java:109)
at com.android.internal.view.menu.MenuItemImpl.createItemView(MenuItemImpl.java:594)
at com.android.internal.view.menu.MenuItemImpl.getItemView(MenuItemImpl.java:577)
at com.android.internal.view.menu.IconMenuView.updateChildren(IconMenuView.java:351)
at com.android.internal.view.menu.IconMenuView.initialize(IconMenuView.java:333)
at com.android.internal.view.menu.MenuBuilder$MenuType.getMenuView(MenuBuilder.java:199)
at com.android.internal.view.menu.MenuBuilder.getMenuView(MenuBuilder.java:323)
at com.android.internal.policy.impl.PhoneWindow.initializePanelContent(PhoneWindow.java:858)
at com.android.internal.policy.impl.PhoneWindow.openPanel(PhoneWindow.java:435)
at com.android.internal.policy.impl.PhoneWindow.onKeyUpPanel(PhoneWindow.java:621)
at com.android.internal.policy.impl.PhoneWindow.onKeyUp(PhoneWindow.java:1339)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1668)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
at android.widget.TabHost.dispatchKeyEvent(TabHost.java:278)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:1687)
at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1120)
at android.app.Activity.dispatchKeyEvent(Activity.java:2073)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1663)
at android.view.ViewRoot.deliverKeyEventToViewHierarchy(ViewRoot.java:2560)
at android.view.ViewRoot.handleFinishedEvent(ViewRoot.java:2535)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1867)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3647)
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:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
I'm getting the same error on an application I've developed for Android 2.1 and Android 2.2 but run on Android 4.0.1 ICS. The same app would run on Android 2.1 but cause a crash with the above error on ICS. If you're drawing something relatively big to the size of the screen, consider checking from that place.

Categories

Resources