-2

For Activity A and B i have set attribute android:noHistory = true in manifest. Activity B is quite heavy , so that's why i am calling intent in thread to open that activity , But problem is after loading whole app just crashes and famous unexpected error occur with Force close button. any solutions appreciated.

Here lies Activity A:

public class FirstActivity extends Activity {

    private static int PROGRESSSECONDS = 4;
    private static Handler FirstActivityHandler;
    private ProgressBar pb;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_first);

        FirstActivityHandler = new Handler(){
            @Override
            public void handleMessage(Message msg) {
                pb.setProgress(msg.arg1);
            }
        };
    }

    public void PlayNowAction(View v) {
        setContentView(R.layout.loadingscreen);
        pb = (ProgressBar) findViewById(R.id.pbLoader);
        pb.setMax(PROGRESSSECONDS);
        pb.setProgress(0);

        new Thread(new Runnable() {

            @Override
            public void run() {
                try {
                    for (int i = 1; i <= PROGRESSSECONDS; i++) {
                        Thread.sleep(1000);
                        Message msg = Message.obtain();
                        msg.arg1 = i;
                        FirstActivityHandler.sendMessage(msg);
                    }

                } catch (InterruptedException e) {

                } finally {
                    Intent in = new Intent(FirstActivity.this,
                            PointsDrawerActivity.class);
                    startActivity(in);
                }
            }
        }).start();

    }
}

Here lies Activity B:

public class PointsDrawerActivity extends Activity{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_first);

        addReccords(); // this a working method but it takes very long time
    }

}

Here lies my LogCat:

07-19 18:22:45.492: D/gralloc_goldfish(1460): Emulator without GPU emulation detected.
07-19 18:22:57.052: D/dalvikvm(1460): GC_EXTERNAL_ALLOC freed 84K, 48% free 2809K/5379K, external 716K/1038K, paused 8ms
07-19 18:23:01.132: D/dalvikvm(1460): GC_EXTERNAL_ALLOC freed 17K, 48% free 2815K/5379K, external 1264K/1776K, paused 9ms
07-19 18:23:01.173: D/dalvikvm(1460): GC_EXTERNAL_ALLOC freed 44K, 49% free 2789K/5379K, external 11634K/13682K, paused 0ms
07-19 18:23:01.213: D/dalvikvm(1460): GC_EXTERNAL_ALLOC freed 16K, 49% free 2775K/5379K, external 22798K/24846K, paused 7ms
07-19 18:23:01.213: E/dalvikvm-heap(1460): 11312112-byte external allocation too large for this process.
07-19 18:23:01.232: D/dalvikvm(1460): GC_FOR_MALLOC freed 0K, 49% free 2775K/5379K, external 22798K/24846K, paused 7ms
07-19 18:23:01.232: E/GraphicsJNI(1460): VM won't let us allocate 11312112 bytes
07-19 18:23:01.232: D/skia(1460): --- decoder->decode returned false
07-19 18:23:01.242: D/AndroidRuntime(1460): Shutting down VM
07-19 18:23:01.242: W/dalvikvm(1460): threadid=1: thread exiting with uncaught exception (group=0xb5fa34f0)
07-19 18:23:01.242: E/AndroidRuntime(1460): FATAL EXCEPTION: main
07-19 18:23:01.242: E/AndroidRuntime(1460): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
07-19 18:23:01.242: E/AndroidRuntime(1460):     at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
07-19 18:23:01.242: E/AndroidRuntime(1460):     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:460)
07-19 18:23:01.242: E/AndroidRuntime(1460):     at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:336)
07-19 18:23:01.242: E/AndroidRuntime(1460):     at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:359)
07-19 18:23:01.242: E/AndroidRuntime(1460):     at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:385)
07-19 18:23:01.242: E/AndroidRuntime(1460):     at com.jutt.dotbot.DotedImage.<init>(DotedImage.java:31)
07-19 18:23:01.242: E/AndroidRuntime(1460):     at com.jutt.dotbot.PointsDrawerActivity.addImagesObject(PointsDrawerActivity.java:274)
07-19 18:23:01.242: E/AndroidRuntime(1460):     at com.jutt.dotbot.PointsDrawerActivity.onCreate(PointsDrawerActivity.java:85)
07-19 18:23:01.242: E/AndroidRuntime(1460):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-19 18:23:01.242: E/AndroidRuntime(1460):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
07-19 18:23:01.242: E/AndroidRuntime(1460):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
07-19 18:23:01.242: E/AndroidRuntime(1460):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
07-19 18:23:01.242: E/AndroidRuntime(1460):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
07-19 18:23:01.242: E/AndroidRuntime(1460):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-19 18:23:01.242: E/AndroidRuntime(1460):     at android.os.Looper.loop(Looper.java:130)
07-19 18:23:01.242: E/AndroidRuntime(1460):     at android.app.ActivityThread.main(ActivityThread.java:3683)
07-19 18:23:01.242: E/AndroidRuntime(1460):     at java.lang.reflect.Method.invokeNative(Native Method)
07-19 18:23:01.242: E/AndroidRuntime(1460):     at java.lang.reflect.Method.invoke(Method.java:507)
07-19 18:23:01.242: E/AndroidRuntime(1460):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-19 18:23:01.242: E/AndroidRuntime(1460):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-19 18:23:01.242: E/AndroidRuntime(1460):     at dalvik.system.NativeStart.main(Native Method)
Zulqurnain Jutt
  • 298
  • 3
  • 20

1 Answers1

1

I'm afraid the actual problem is with using bitmaps. Your app is suffering from the infamous OutOfMemoryError, which is doomed to happen if your app has anything to do with a few bitmaps. It is necessary to handle them. Here's a way to do it : OutOfMemoryError resolution

Community
  • 1
  • 1
  • awesome , thanks , i noted i was using a class in activity B , which is actually storing bitmaps , which i was not using ! , i removed that everything works like a charm :) – Zulqurnain Jutt Jul 19 '15 at 13:46