Thanks Dianne for response. Finally I got a solution to reset the
static variables. My onCreate() looks lik,

private static boolean isCreatedAlready = false;
    protected void onCreate(Bundle b) {
        super.onCreate(b);
        // fix to reset all static variables
        if(isCreatedAlready){
            Intent myIntent = new Intent(this, this.getClass());
            startActivity(myIntent);
            System.exit(0);
        }
        isCreated = true;
        Log.i("LCM", "MIDlet.onCreate");
    }

Basically, I am creating and launching an activity with the intent of
current activity (which retains the value of statics) and also killing
the current one after that. In the new activity all vaules are reset
to default values. It's serving my purpose absolutely well.

Now I would like to ask you why you are not recomending System.exit(0)
anymore? Is there any thing can be broken in the activity lifecycle if
we do that?

Again thanks in advance. I will be happy if you find time to answer
me. :)

Rgds,
Sujoy

On Dec 2, 3:40 am, Dianne Hackborn <[email protected]> wrote:
> Please do not use System.exit().
>
> Your process is kept around after the user exits, by design, so it doesn't
> need to be re-initialized if they return to it soon after.  This is the way
> things are supposed to work.  If you have lots of data in statics, you
> should add something to remove the references to it when your (last)
> activity is destroyed, so the garbage collector can free it.
>
> Also about Bundle -- if you have so much data in statics that you are
> concerned about its space after your activity exits, you really should not
> be putting all of that data in Bundle as part of your save state.  You need
> to be pretty light weight in what you do there, and take care of
> re-constructing any heavy data you can later when needed.
>
> On Mon, Nov 30, 2009 at 10:54 PM, Sujoy Ghosh <[email protected]>wrote:
>
>
>
>
>
> > Hi,
>
> > I have been facing problems to manage statics variables used in my
> > android application. If we exit the application against a particular
> > event (touch or key event -which is must for my app), all the statics
> > variables are retaining the values when I am launching it again. I am
> > invoking Activity.finish() method for termination .
> > I know there is a collection type class available called Bundle and we
> > can use it to save the states of all the statics and get those back
> > when again creating the same activity during relaunch, but it would be
> > a hard task if we want to port some  j2me applications to Android
> > because of having thousands of statics variables. Is there any way to
> > kill the application completely including all the statics variable
> > used there?
>
> > I tried with System.exit(0) and it works well for Android G1 and G2
> > (tested in firmware 1.6). But in Android Robyn (prototype) the same
> > causes a major defect ("Activity not responding" popup apears just
> > after exit) and I came to know from android dev forum that calling
> > System.exit(0) is not recommended for termination of an activity.
>
> > I would appreciate if someone can provide me a solution. Thanks in
> > advance.
>
> > Rgds,
> > Sujoy
>
> > --
> > 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%2bunsubs­[email protected]>
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en
>
> --
> Dianne Hackborn
> Android framework engineer
> [email protected]
>
> Note: please don't send private questions to me, as I don't have time to
> provide private support, and so won't reply to such e-mails.  All such
> questions should be posted on public forums, where I and others can see and
> answer them.- Hide quoted text -
>
> - Show quoted text -

-- 
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