I have A TabActivity that hosts other activities, on the tabactivity I have a broadcast receiver that gets data from a webservice(not an android Service) class. The webservice class makes a http request in an asynctask and returns the data by sending broadcast message to the tabhost.
If I block the screen on portrait, the data is retrieved with no problems, if I let the screen in default mode (portrait and landscape), at first run the application is getting the data but after several orientation screen changes, the app is crashing and I receive the following error:
11-03 17:25:48.542: ERROR/AndroidRuntime(16486): FATAL EXCEPTION: main
java.lang.RuntimeException: Error receiving broadcast Intent { act=x.tableManager.tableData.success } in x.SolarObjTableMain$TableViewDataReceiver@405c5d88
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:756)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:4196)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at x.SolarObjTableMain.getPaddedData(SolarObjTableMain.java:530)
at x.SolarObjTableMain.addTableToList(SolarObjTableMain.java:983)
at x.SolarObjTableMain.access$900(SolarObjTableMain.java:35)
at x.SolarObjTableMain$TableViewDataReceiver.onReceive(SolarObjTableMain.java:1051)
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:739)
... 9 more
After the first crash, the app is keep crashing at the first run, I don’t have to shake the phone or rotate it to reproduce the error…
After some break points, it seems that the receiver gets some data but after a random amount of data received, all objects in the activity gets to null.
Note that I am registering the receiver in onCreate() and onResume() and unregister it in onPause().
What I am doing wrong? Thank you!
You’re registering in onCreate AND onResume? Just do onResume.
Also, your life would be easier if you add this to the activity declaration in AndroidManifest.xml
android:configChanges=”orientation|keyboard|keyboardHidden”
It will prevent a complete restart of your activity on orientation changes (as well as keyboard events).
I’m not sure why you’re getting nulls, but I think if you change those two things, you should be good. If not, we’d need some code to look at.