Search code examples
javaandroidout-of-memoryshowcaseviewsamsung-galaxy

ShowCaseView Out of Memory Error


I`m having some trouble with the Galaxy S family, the showcase view works flawless in any other device, but I get the following error on Galaxy S devices.

java.lang.OutOfMemoryError: Failed to allocate a 5760012 byte allocation with 3573238 free bytes and 3MB until OOM at dalvik.system.VMRuntime.newNonMovableArray(VMRuntime.java) at android.graphics.BitmapFactory.nativeDecodeAsset(BitmapFactory.java)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:726)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:547)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1014)
at android.content.res.Resources.loadDrawableForCookie(Resources.java:3747)
at android.content.res.Resources.loadDrawable(Resources.java:3620) at android.content.res.Resources.getDrawable(Resources.java:1852) at android.support.v4.content.res.ResourcesCompatApi21.getDrawable(ResourcesCompatApi21.java)
at android.support.v4.content.res.ResourcesCompat.getDrawable(ResourcesCompat.java)
at com.github.amlcurran.showcaseview.StandardShowcaseDrawer.(StandardShowcaseDrawer.java)
at com.github.amlcurran.showcaseview.ShowcaseView.(ShowcaseView.java)
at com.github.amlcurran.showcaseview.ShowcaseView.(ShowcaseView.java)
at com.github.amlcurran.showcaseview.ShowcaseView$Builder.(ShowcaseView.java)
at com.github.amlcurran.showcaseview.ShowcaseView$Builder.(ShowcaseView.java)
at br.com.mygas.myapplication.MainActivity.showcase(MainActivity.java)
at br.com.mygas.myapplication.MainActivity.access$300(MainActivity.java)
at br.com.mygas.myapplication.MainActivity$5.onShowcaseViewDidHide(MainActivity.java)
at com.github.amlcurran.showcaseview.ShowcaseView$2.onAnimationEnd(ShowcaseView.java)
at com.github.amlcurran.showcaseview.AnimatorAnimationFactory$2.onAnimationEnd(AnimatorAnimationFactory.java)
at android.animation.ValueAnimator.endAnimation(ValueAnimator.java:1089)
at android.animation.ValueAnimator$AnimationHandler.doAnimationFrame(ValueAnimator.java:666)
at android.animation.ValueAnimator$AnimationHandler.run(ValueAnimator.java:682)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:777)
at android.view.Choreographer.doCallbacks(Choreographer.java:590) at
android.view.Choreographer.doFrame(Choreographer.java:559) at
android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:763)
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:5942) at
java.lang.reflect.Method.invoke(Method.java) at
java.lang.reflect.Method.invoke(Method.java:372) at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)

And this is the code implemented that produces the above error:

private void showcase() {
        if (SaveSharedPreference.isMainActivity(this)) {
            switch (counter) {
                case 0:
                    new ShowcaseView.Builder(this)
                            .withMaterialShowcase()
                            .setContentTitle("Esta é a tela inicial:")
                            .setStyle(R.style.CustomShowcaseThemeNext)
                            .setShowcaseEventListener(new SimpleShowcaseEventListener() {
                                @Override
                                public void onShowcaseViewDidHide(ShowcaseView showcaseView) {
                                    counter++;
                                    showcase();
                                }
                            })
                            .build();
                    break;

                case 1:
                    new ShowcaseView.Builder(this)
                            .setContentTitle("Selecione o tipo de combustível:")
                            .setTarget(new ViewTarget(R.id.spinner, this))
                            .setShowcaseDrawer(new CustomShowcaseView(this, findViewById(R.id.spinner).getWidth(), findViewById(R.id.spinner).getHeight()))
                            .setShowcaseEventListener(new SimpleShowcaseEventListener() {
                                @Override
                                public void onShowcaseViewDidHide(ShowcaseView showcaseView) {
                                    counter++;
                                    showcase();
                                }
                            })
                            .build();
                    break;

                case 2:
                    new ShowcaseView.Builder(this)
                            .withMaterialShowcase()
                            .setTarget(new ViewTarget(R.id.fab2, this))
                            .setContentTitle("Clique neste botão para procurar combustível ao redor:")
                            .setStyle(R.style.CustomShowcaseThemeNext)
                            .setShowcaseEventListener(new SimpleShowcaseEventListener() {
                                @Override
                                public void onShowcaseViewDidHide(ShowcaseView showcaseView) {
                                    counter++;
                                    showcase();
                                }
                            })
                            .build();
                    break;

                case 3:
                    new ShowcaseView.Builder(this)
                            .withMaterialShowcase()
                            .setTarget(new ViewTarget(R.id.fab2, this))
                            .setContentTitle("Lembre-se:")
                            .setContentText("É necessário estar com o GPS ligado")
                            .setStyle(R.style.CustomShowcaseTheme2)
                            .setShowcaseEventListener(new SimpleShowcaseEventListener() {
                                @Override
                                public void onShowcaseViewDidHide(ShowcaseView showcaseView) {
                                    counter++;
                                    showcase();
                                }
                            })
                            .build();
                    SaveSharedPreference.mainActivityFirst(this);
                    break;
            }
        }
    }

I can't work out where the error is coming from so looking for any advice.


Solution

  • The problem was solved changing the method hide from ShowcaseView.java From this:

    @Override
        public void hide() {
            // If the type is set to one-shot, store that it has shot
            shotStateStore.storeShot();
            mEventListener.onShowcaseViewHide(this);
            fadeOutShowcase();
        }
    

    To this:

    @Override
        public void hide() {
            // If the type is set to one-shot, store that it has shot
            clearBitmap();
            shotStateStore.storeShot();
            mEventListener.onShowcaseViewHide(this);
            fadeOutShowcase();
        }