1

I have worked on the application which I present in the RAM after I am out of my application. Also the size in RAM is increases every time when I play the application. I don't know why it is happening. Please suggest me something.

Also I am using timer in my application for 15 sec and after completing the time I show I Dialog that Your time is over. But some times that dialog appear 3-4 times on one time finish of time. This is very embarrassing for my application. Is this thing is due to the app is in background or anything wrong with my timer. Code of timer is below. Globally declare the

MyCount counter = new MyCount(time, 1000); 

and the timer code is:

     public class MyCount extends CountDownTimer {

            public MyCount(long millisInFuture, long countDownInterval) {
                super(millisInFuture, countDownInterval);
            }


        //call when time is finish 
        public void onFinish() {
            // TODO Auto-generated method stub
            AlertDialog.Builder alertbox = new AlertDialog.Builder(game.this);
            alertbox.setMessage("Oops, your time is over");
            alertbox.setNeutralButton("Ok",
                    new DialogInterface.OnClickListener() {

                        // Click listener on the neutral button of alert box
                        public void onClick(DialogInterface arg0, int arg1) {
                            quesCount++;
                            for(int i=0;i<4;i++){
                                 btn[i].setVisibility(View.VISIBLE);
                             }

                            rndom_no=randomno();
                            showDataOverControls(rndom_no);
                            counter.start();
    }
            });
            alertbox.show();
        }

        @Override
        public void onTick(long millisUntilFinished) {
            time1 = (TextView) findViewById

(R.id.time);

        time1.setText(""+millisUntilFinished / 1000);
    }
}

The for loop inside the application change the visibility of the buttons, rndom_no=randomno(); this function generate the random numbers, showDataOverControls(rndom_no); it fetch the data from the xml file by xml parsing. Please suggest if I am doing something wrong.

Widor
  • 13,003
  • 7
  • 42
  • 64
ADB
  • 567
  • 2
  • 5
  • 20

2 Answers2

1

Your app stays in ram as long as android wants it.. You don't have control to it.

Try reusing the activities by configuring the launchMode property to stop it from increasing.

Also, use some flag to check the dialog box display and don't display if it's already displayed

kishu27
  • 3,140
  • 2
  • 26
  • 41
  • "Try reusing the activities by configuring the launchMode property to stop it from increasing. " This is not clear to me can u please tell me how can we do that. My app size every time increases in the Ram when I use it – ADB May 14 '12 at 14:34
  • When you leave the activities without a `launchMode` specification in manifest.xml, they are not reused but recreated everytime the activities are launched. You have to override this behavior by specifying the `launchMode` property for the node of the activity in the manifest. Check this link for info http://stackoverflow.com/questions/2424488/android-new-intent-starts-new-instance-with-androidlaunchmode-singletop And the related documentation at: http://developer.android.com/intl/de/guide/topics/manifest/activity-element.html – kishu27 May 14 '12 at 14:38
1

You app stays in the phone ram to allow the user to return to the app without much loading time. The Android memory system works in a way that as long as memory is not needed the last used apps stay in the RAM. Don't worry about that. If another app needs this memory and your app has no foreground components like activities your whole app will closed down step by step until the phone has enough memory again. The only way to block memory would it be to create a very badly designed service. And even services are shut down if foreground services need the memory.

Janusz
  • 187,060
  • 113
  • 301
  • 369
  • 1
    But why this is increases every time when I use the application. means my app size is 6mb then next time when I play it the size become 7.5mb in RAM. I didn't understand this thing. Also u have seen the timer issue which I have raised also a big flow in my app. How can I manage that ? plz suggest me something :( – ADB May 15 '12 at 06:57
  • May u please guide me how can I handle this issue – ADB May 15 '12 at 07:27