0

I am writing an android application and I need to have two classes use the same KeyguardLock object but I am experiencing extreme difficulty in sharing (via serialization) that object. I have tried using the serialization stackoverflow example link but that didn't work at all. I get a "not serializable" IO exception trying to save the object. I have also tried using JSONObject.

Any ideas? Has anyone run into a similar problem?

Community
  • 1
  • 1
David Gill
  • 8,411
  • 5
  • 19
  • 21
  • Also worth noting that I have to use the same object as using keyguardManager.newKeyguardLock(Activity.KEYGUARD_SERVICE) twice causes issues. See [android issue 14246](http://code.google.com/p/android/issues/detail?id=14246) – David Gill Feb 05 '11 at 05:51

1 Answers1

0

Why are you trying to serialize it? A object can only be serialize if it implements Serializable which KeyguardLock doesn't.

If you're trying to pass it around Activities, either create a custom Application object and store it there. Or use a public static variable in a class and access it via that. The static variable is probably the better option for this.

Chris Banes
  • 31,763
  • 16
  • 59
  • 50
  • Never mind, your solution works. I think I need to revamp my knowledge of public static as I didn't know it behaved in that manor. I'll leave the code up below as an example to other people with a similar problem. – David Gill Feb 05 '11 at 17:06