Hi,

Try initiallizing them to null before the change of activity takes place or
at the start of home activity. Since your application is not closed(scope of
the static objects), the static objects are there in memory allocated to
that process and hence retain the value that you give.

Thanks & Regards,
Yousuf Syed




On Sat, Jan 2, 2010 at 2:27 AM, Alok Kulkarni <kulsu...@gmail.com> 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 here
> http://groups.google.com/group/android-developers/browse_thread/thread/4c1b8955ebfd5799?pli=1
> 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 Beginners" group.
>
> NEW! Try asking and tagging your question on Stack Overflow at
> http://stackoverflow.com/questions/tagged/android
>
> To unsubscribe from this group, send email to
> android-beginners+unsubscr...@googlegroups.com<android-beginners%2bunsubscr...@googlegroups.com>
> For more options, visit this group at
> http://groups.google.com/group/android-beginners?hl=en
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.

NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android

To unsubscribe from this group, send email to
android-beginners+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en

Reply via email to