[mono-android] Crash on HTC
Jonathan Pryor
jonp at xamarin.com
Mon Jun 18 21:12:14 UTC 2012
On Jun 18, 2012, at 11:35 AM, Jonathan Chapman wrote:
> The reason the null reference is happening is that the object is gone.
Are you sure it's the same process?
Each line in the Android Debug Log contains a process id (pid):
http://docs.xamarin.com/android/advanced_topics/android_debug_log#Interesting_Messages
It's possible that your process is launched, you go "elsewhere" for a bit, and Android nukes your process. Later your process is needed, so Android creates a new process, but it's "missed' whatever state you're expecting.
You can see if this is happening by reading the Android Debug Log: do you see multiple __mono_init__ messages within the timeframe you're dealing with? Each __mono_init__ message will be from a different process (check the pid to confirm).
If process restart is the problem, then what you need to do is preserve your app state within Activity.OnSaveInstanceState(), or perhaps instead use a Service to contain your static data so that "something" is always running. (Android can still nuke your process if you have Services running, but presumably it'll nuke your process _later_ than it would otherwise, and your static member init + cleanup logic can be centralized in the Service lifecycle logic.)
If process restart isn't the problem, we'll sadly need more information. Android debug logs and logging would be a good start. ;-)
- Jon
More information about the Monodroid
mailing list