[android-developers] Re: Weird: It appears as if sometimes my Activity will be resumed but previously set instance variables are null

2010-04-21 Thread Bob Kerns
Or use the debugger, and set breakpoints in each method on the
affected class, and step through until you see where the field is
being cleared.

On Apr 20, 8:23 pm, Dianne Hackborn hack...@android.com wrote:
 Fwiw, there is definitely no clearing of instance variables when
 onNewIntent() is called.  I can't imagine how the framework would even clear
 instance variables, except for using reflection to find them and poke them,
 which we definitely don't do.

 For these situations it may be useful to look at the event log (adb logcat
 -b events) to see what the system is doing, and also possibly the activity
 manager state (adb shell dumpsys activity) to see the state the system has
 your activities in.

 On Tue, Apr 20, 2010 at 9:48 AM, Christopher christopher...@gmail.comwrote:





  Just out of curiosity, is your Activity making use of onNewIntent()?
  I was curious because I recently worked on an Activity that did, and
  found that many variables in the Activity were set to null after this
  method completed.  It's almost as if onNewIntent does a quick reset of
  the instance, which given the nature of onNewIntent could make sense.
  I might not be 100% accurate in terms of what's going on, but thought
  perhaps the information could help.

  (Note: I think I originally replied only to the author, so I attempted
  to reconstruct the post as best I could.  I apologize if suddenly
  there are two almost identical posts from me that show up).

  Christopher

  --
  You received this message because you are subscribed to the Google
  Groups Android Developers group.
  To post to this group, send email to android-developers@googlegroups.com
  To unsubscribe from this group, send email to
  android-developers+unsubscr...@googlegroups.comandroid-developers%2Bunsubs 
  cr...@googlegroups.com
  For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en

 --
 Dianne Hackborn
 Android framework engineer
 hack...@android.com

 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.

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.com
 For more options, visit this group 
 athttp://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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Weird: It appears as if sometimes my Activity will be resumed but previously set instance variables are null

2010-04-20 Thread Bob Kerns
I do this, without any issues at all.

How are you getting your Application instance from your activities?
not getApplicationContext() I hope...

Have you examined the state from the debugger? There may be something
you're missing about the state of things.

On Apr 19, 11:41 pm, patbenatar patbena...@gmail.com wrote:
 Hey all-

 I am using an Application object to store app-wide instance data--data
 that I need to remain in existence for the entire lifetime of the app,
 so the Application class seems like the proper place to put it. I have
 just finished reading this 
 threadhttp://groups.google.com/group/android-developers/browse_thread/threa...
 that goes into pretty good detail and receives confirmation from
 Googler hackbod as to how the Application class performs--and from
 that info it seems this strange behavior I am receiving should not be
 happening...

 Basically, every once in a while when I resume my app in any of its
 Activities (it is still running in memory so onCreate is not called) I
 get NullPointerExceptions because instance variables in my Application
 class are returning null when I request them from my Activity (via a
 getter method in my custom Application class). It seems as if
 sometimes Android saves the states of my Activities but deletes all my
 instance variable data... This can't be an Android problem--there must
 be something wrong with my code.

 Has anyone else ever ran into an issue of this kind? Any ideas as to
 what may be causing this? I'm not going to post my code here as that
 won't help anyone, but hopefully someone can point me in some helpful
 directions.

 Thanks so much,
 Nick

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.com
 For more options, visit this group 
 athttp://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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Weird: It appears as if sometimes my Activity will be resumed but previously set instance variables are null

2010-04-20 Thread patbenatar
Bob-

Nope, I'm using getApplication()

For instance [inside an Activity]:


MyApplication application;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
application = (MyApplication) this.getApplication();
}


The error is most easily re-produceable when I am in Activity B, after
A started it for result, and then click a button in B to launch Maps
with an Intent to search for an address, then from Maps I hit Home
then my launcher icon on my Home Screen to go back into my app--BAM!
Activity B fails onResume with a NullPointerException coming from a
getter method on my MyApplication class, when I know for sure Activity
A properly set the data in MyApplication..

So strange...

Thanks,
Nick



On Apr 20, 2:18 am, Bob Kerns r...@acm.org wrote:
 I do this, without any issues at all.

 How are you getting your Application instance from your activities?
 not getApplicationContext() I hope...

 Have you examined the state from the debugger? There may be something
 you're missing about the state of things.

 On Apr 19, 11:41 pm, patbenatar patbena...@gmail.com wrote:





  Hey all-

  I am using an Application object to store app-wide instance data--data
  that I need to remain in existence for the entire lifetime of the app,
  so the Application class seems like the proper place to put it. I have
  just finished reading this 
  threadhttp://groups.google.com/group/android-developers/browse_thread/threa...
  that goes into pretty good detail and receives confirmation from
  Googler hackbod as to how the Application class performs--and from
  that info it seems this strange behavior I am receiving should not be
  happening...

  Basically, every once in a while when I resume my app in any of its
  Activities (it is still running in memory so onCreate is not called) I
  get NullPointerExceptions because instance variables in my Application
  class are returning null when I request them from my Activity (via a
  getter method in my custom Application class). It seems as if
  sometimes Android saves the states of my Activities but deletes all my
  instance variable data... This can't be an Android problem--there must
  be something wrong with my code.

  Has anyone else ever ran into an issue of this kind? Any ideas as to
  what may be causing this? I'm not going to post my code here as that
  won't help anyone, but hopefully someone can point me in some helpful
  directions.

  Thanks so much,
  Nick

  --
  You received this message because you are subscribed to the Google
  Groups Android Developers group.
  To post to this group, send email to android-developers@googlegroups.com
  To unsubscribe from this group, send email to
  android-developers+unsubscr...@googlegroups.com
  For more options, visit this group 
  athttp://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 android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.com
 For more options, visit this group 
 athttp://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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Weird: It appears as if sometimes my Activity will be resumed but previously set instance variables are null

2010-04-20 Thread westmeadboy
Not sure if this helps, but use
http://developer.android.com/reference/java/lang/System.html#identityHashCode(java.lang.Object)
to check whether the Application object is indeed the same in both
cases (or whether they are in different DVMs)

On Apr 20, 12:04 pm, patbenatar patbena...@gmail.com wrote:
 Bob-

 Nope, I'm using getApplication()

 For instance [inside an Activity]:

 MyApplication application;

 @Override
 public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     application = (MyApplication) this.getApplication();

 }

 The error is most easily re-produceable when I am in Activity B, after
 A started it for result, and then click a button in B to launch Maps
 with an Intent to search for an address, then from Maps I hit Home
 then my launcher icon on my Home Screen to go back into my app--BAM!
 Activity B fails onResume with a NullPointerException coming from a
 getter method on my MyApplication class, when I know for sure Activity
 A properly set the data in MyApplication..

 So strange...

 Thanks,
 Nick

 On Apr 20, 2:18 am, Bob Kerns r...@acm.org wrote:





  I do this, without any issues at all.

  How are you getting your Application instance from your activities?
  not getApplicationContext() I hope...

  Have you examined the state from the debugger? There may be something
  you're missing about the state of things.

  On Apr 19, 11:41 pm, patbenatar patbena...@gmail.com wrote:

   Hey all-

   I am using an Application object to store app-wide instance data--data
   that I need to remain in existence for the entire lifetime of the app,
   so the Application class seems like the proper place to put it. I have
   just finished reading this 
   threadhttp://groups.google.com/group/android-developers/browse_thread/threa...
   that goes into pretty good detail and receives confirmation from
   Googler hackbod as to how the Application class performs--and from
   that info it seems this strange behavior I am receiving should not be
   happening...

   Basically, every once in a while when I resume my app in any of its
   Activities (it is still running in memory so onCreate is not called) I
   get NullPointerExceptions because instance variables in my Application
   class are returning null when I request them from my Activity (via a
   getter method in my custom Application class). It seems as if
   sometimes Android saves the states of my Activities but deletes all my
   instance variable data... This can't be an Android problem--there must
   be something wrong with my code.

   Has anyone else ever ran into an issue of this kind? Any ideas as to
   what may be causing this? I'm not going to post my code here as that
   won't help anyone, but hopefully someone can point me in some helpful
   directions.

   Thanks so much,
   Nick

   --
   You received this message because you are subscribed to the Google
   Groups Android Developers group.
   To post to this group, send email to android-developers@googlegroups.com
   To unsubscribe from this group, send email to
   android-developers+unsubscr...@googlegroups.com
   For more options, visit this group 
   athttp://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 android-developers@googlegroups.com
  To unsubscribe from this group, send email to
  android-developers+unsubscr...@googlegroups.com
  For more options, visit this group 
  athttp://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 android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.com
 For more options, visit this group 
 athttp://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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Weird: It appears as if sometimes my Activity will be resumed but previously set instance variables are null

2010-04-20 Thread String
On Apr 20, 12:47 pm, Mark Murphy mmur...@commonsware.com wrote:

 It is entirely possible that your activities and application were
 destroyed while you were in the Maps and Home applications, to free up
 memory.

Sure, that's the normal app lifecycle. But if this is the case, why
isn't the Activity's onCreate being called? To me, that's the
confusing part of this.

String

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


Re: [android-developers] Re: Weird: It appears as if sometimes my Activity will be resumed but previously set instance variables are null

2010-04-20 Thread Mark Murphy
String wrote:
 On Apr 20, 12:47 pm, Mark Murphy mmur...@commonsware.com wrote:
 
 It is entirely possible that your activities and application were
 destroyed while you were in the Maps and Home applications, to free up
 memory.
 
 Sure, that's the normal app lifecycle. But if this is the case, why
 isn't the Activity's onCreate being called? To me, that's the
 confusing part of this.

Whoops. I missed that part. If that's happening, that is very strange.
The Application object should be the second-to-last thing to go -- if
activities are in RAM, so should the Application, AFAIK.

That being said, the *last* thing to go is static data members, since
they'll only get cleaned up when the whole Dalvik VM is reset or the
process is fully terminated. It may be worth a test to see if a static
data member survives all of this.

Something definitely is not adding up.

My apologies for missing that part of the original post and not
addressing it in my earlier reply.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy

_Android Programming Tutorials_ Version 2.0 Available!

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


[android-developers] Re: Weird: It appears as if sometimes my Activity will be resumed but previously set instance variables are null

2010-04-20 Thread Christopher
Just out of curiosity, is your Activity making use of onNewIntent()?
I was curious because I recently worked on an Activity that did, and
found that many variables in the Activity were set to null after this
method completed.  It's almost as if onNewIntent does a quick reset of
the instance, which given the nature of onNewIntent could make sense.
I might not be 100% accurate in terms of what's going on, but thought
perhaps the information could help.


(Note: I think I originally replied only to the author, so I attempted
to reconstruct the post as best I could.  I apologize if suddenly
there are two almost identical posts from me that show up).


Christopher

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


[android-developers] Re: Weird: It appears as if sometimes my Activity will be resumed but previously set instance variables are null

2010-04-20 Thread patbenatar
Thanks for all the input guys--

Mark, it is indeed very strange that my Activity's onCreate is not
being called here. And the reason I have chosen not to use a database
or flat file is because the lifetime of this data is a maximum of 20
minutes before my app rules it outdated and fetches new data from the
server. Didn't really see the point in writing data with such a short
shelf life to a more permanent data store. If my app is destroyed and
relaunched within this 20 minute period, I have no problem with doing
a fresh API fetch (why not? the more frequently [while remaining un-
invasive] I can update the data, the better)... I will throw

Christopher, nope not overring onNewIntent--sounds like some weird
behavior you've run into there...

Is it possible that a memory leak could possibly be the cause of this
behavior? I had some leaks previously but went through all my code a
couple weeks ago and believe I have removed them all but I haven't
completely confirmed this [although my app hasn't hit any OutOfMemory
errors since then]. I don't see why a memory leak would be removing
data though, normally they causes data to pile up...

I have found one issue in my code that may resolve this.. I
implemented a potential fix but have not had a chance to test on my
device yet. Will post back. In the meanwhile, anyone else with
thoughts on this matter, please share :)

Nick



On Apr 20, 9:48 am, Christopher christopher...@gmail.com wrote:
 Just out of curiosity, is your Activity making use of onNewIntent()?
 I was curious because I recently worked on an Activity that did, and
 found that many variables in the Activity were set to null after this
 method completed.  It's almost as if onNewIntent does a quick reset of
 the instance, which given the nature of onNewIntent could make sense.
 I might not be 100% accurate in terms of what's going on, but thought
 perhaps the information could help.

 (Note: I think I originally replied only to the author, so I attempted
 to reconstruct the post as best I could.  I apologize if suddenly
 there are two almost identical posts from me that show up).

 Christopher

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.com
 For more options, visit this group 
 athttp://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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Re: Weird: It appears as if sometimes my Activity will be resumed but previously set instance variables are null

2010-04-20 Thread Dianne Hackborn
Fwiw, there is definitely no clearing of instance variables when
onNewIntent() is called.  I can't imagine how the framework would even clear
instance variables, except for using reflection to find them and poke them,
which we definitely don't do.

For these situations it may be useful to look at the event log (adb logcat
-b events) to see what the system is doing, and also possibly the activity
manager state (adb shell dumpsys activity) to see the state the system has
your activities in.

On Tue, Apr 20, 2010 at 9:48 AM, Christopher christopher...@gmail.comwrote:

 Just out of curiosity, is your Activity making use of onNewIntent()?
 I was curious because I recently worked on an Activity that did, and
 found that many variables in the Activity were set to null after this
 method completed.  It's almost as if onNewIntent does a quick reset of
 the instance, which given the nature of onNewIntent could make sense.
 I might not be 100% accurate in terms of what's going on, but thought
 perhaps the information could help.


 (Note: I think I originally replied only to the author, so I attempted
 to reconstruct the post as best I could.  I apologize if suddenly
 there are two almost identical posts from me that show up).


 Christopher

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en




-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

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.

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