Reputation: 1520
My main activity handles changes into portrait mode just fine. However, if I launch a very simple activity via startActivityForResult()
and switch to portrait mode before finishing it, my main activity crashes because some of its variables are set to null.
It looks like my connection to the Service is not being recreated. I tried manually calling doUnbindService(); doBindService();
inside of onActivityResult()
but onServiceConnected()
is still not being called.
What's the proper way to handle the Activity lifecycle here?
EDIT: I see in the log file that onServiceConnected()
is indeed being called -- but it's being called after onActivityResult()
.
Upvotes: 0
Views: 188
Reputation: 1520
The problem was that I was referring to objects which don't exist until onCreate() is called again. I needed to queue my answers locally and wait for those objects to be recreated to avoid crashes.
Upvotes: 0
Reputation: 1698
For you second Activity add this
if your android:targetSdkVersion="12" or less
android:configChanges="orientation|keyboardHidden">
if your android:targetSdkVersion="13" or more
android:configChanges="orientation|keyboardHidden|screenSize">
in manifest.xml
Upvotes: 2