Sounds like it might be possible that onBackPressed can get called before onCreate in some circumstances where the device is being slow?
If that is at all a possibility, maybe you should check for null in onBackPressed! :-) Doug On Jul 23, 4:00 pm, Zsolt Vasvari <[email protected]> wrote: > I am getting some bugreports of NPE's which I cannot explain. > > These happen rarely. Here's the must baffling (in simplified code): > > class MyActivity extends Activity > { > Object myObject; > > protected void onCreate(Bundle state) > { > myObject = new Object(); > } > > public void onBackPressed() > { > myObject.myMethod(); > } > > } > > Then the user gets a NPE on myObject when it tries to call myMethod in > obBackPressed() > > There are no other myObject assignemnet in my code -- once it's > inialized, it's never touched. So the only way I can see that NPE > happenining is if onBackPressed() is called before onCreate(). > > I've had some other reports where the NPE happened after a screen > rotate, but it involved a member variable, which should have been also > initalized in onCreate(). > > Since these reports are rare with only 1 report per error, I suspect a > race conditiion. > > Would love to hear people's ideas. (And please don't tell me to chech > myObject != null before accessing) -- 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

