Actually i have a seperate class which is instantiated from the Activity
which has these static objects which need to be shared throughout the
application.Thats why i have them static.
Thanks,
Alok.

On Sat, Jan 2, 2010 at 1:20 PM, Brion Emde <[email protected]> wrote:

> What is the reason that your HashMap and arrays are static? Perhaps
> they are a component of each instance of your Activity, rather than
> having a single HashMap and arrays for all instances?
>
>
> On Jan 2, 12:27 am, Alok Kulkarni <[email protected]> wrote:
> > Hi guys, I am facing a problem in my application.
> > I have a few static arrays and Hashmaps in my app which i fill in when my
> > Activity starts.Then this  activity later launches another Activity. Now
> > user presses Home button of Back button and again restarts the app, even
> > then the static objects remain in memory. I beleive this is default
> android
> > behaviour.
> > I have an example app.
> > package com.cm.test;
> >
> > import java.util.HashMap;
> >
> > import android.app.Activity;
> > import android.os.Bundle;
> > import android.util.Log;
> >
> > public class MyActivity extends Activity {
> >     public static HashMap<String, String> hMap = new HashMap<String,
> > String>();
> >
> >     /** Called when the activity is first created. */
> >     @Override
> >     public void onCreate(Bundle savedInstanceState) {
> >         super.onCreate(savedInstanceState);
> >         setContentView(R.layout.main);
> >         Log.i("***","Hash map size = "+hMap.size());
> >
> >         hMap.put("Alok","Alokkkk");
> >         hMap.put("Jitu","Jituuuu");
> >
> >         Log.i("***","Activity onCreate() called");
> >     }
> >     @Override
> >     public void onDestroy()
> >     {
> >         Log.i("***","Activity onDestroy() called");
> >         super.onDestroy();
> >
> >     }
> >
> >     @Override
> >     public void onResume()
> >     {
> >         super.onResume();
> >         Log.i("***","Activity onResume() called");
> >     }
> >     @Override
> >     public void onStop()
> >     {
> >
> >         super.onStop();
> >
> >         Log.i("***","Activity onStop() called");
> >     }
> >
> > }
> >
> > Output First time is Size = 0. for 1st launch, Next for every launch ,
> > HashMap size is 2... If i use ArrayList , the size of ArrayList goes on
> > increasing.
> > I dont want this to happen.One thing was that to clear the HashMap in
> > onDestroy() or in onStop() in case user presses Home button. But my
> Activity
> > launches another ListActivity in it. So the alternae option is to clear
> the
> > Hashmaps in onDestroy() | onStop() of this activity.
> > I am not much clear when the Activity exits. From the posts that i have
> read
> > i found few things herehttp://
> groups.google.com/group/android-developers/browse_thread/threa...
> > The manifest part android:clearTaskOnLaunch=true does not work in my
> case.
> > What do you people suggest in this case?
> > Thanks,
> > Alok.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]<android-developers%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to