[android-beginners] Re: Get preferences from xml/preferences.xml
Hi, thank for your help, I have tried the getBaseContext() method, but I get my application stops unexpectedly. When I debug, I get a RuntimeExeption before I get to the SharedPreferences [...] code. This is what the Debug window says: DalvikVM[localhost:8609] Thread [3 main] (Suspended (exception RuntimeException)) ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord) line: 2194 ActivityThread.handleLaunchActivity(ActivityThread$ActivityRecord) line: 2284 ActivityThread.access$1800(ActivityThread, ActivityThread $ActivityRecord) line: 112 ActivityThread$H.handleMessage(Message) line: 1692 ActivityThread$H(Handler).dispatchMessage(Message) line: 99 Looper.loop() line: 123 ActivityThread.main(String[]) line: 3948 Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method] Method.invoke(Object, Object...) line: 521 ZygoteInit$MethodAndArgsCaller.run() line: 782 ZygoteInit.main(String[]) line: 540 NativeStart.main(String[]) line: not available [native method] Thread [13 Binder Thread #2] (Running) Thread [11 Binder Thread #1] (Running) //Kaloer On 11 Maj, 19:52, Cass Surek cass.su...@gmail.com wrote: You could get the context by calling getBaseContext(). Please be more specific on what exactly does not work as your problem might be in another place. Cass On May 11, 5:28 pm, kaloer mkal...@gmail.com wrote: Hi, How do I get the preferences from the preferences.xml file? I have tried with this code: SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences (this); but it does not work. I think the error is coursed by the use of the Context this, because the preferences are set by an other class. How can I access this preferences? Thank you, //Kaloer --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: Get preferences from xml/preferences.xml
I had to roll back to version 1.1 due to not being able to use the emulator with sensors, but this works fine for me : private void getPrefs(){ SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); this.prefsAudioEnabled = sharedPref.getBoolean (audio_enabled, true); } Placed within the main activity of my application. What is right before the call to the prefs? That could be the culprit. Cass On May 11, 7:18 pm, kaloer mkal...@gmail.com wrote: Hi, thank for your help, I have tried the getBaseContext() method, but I get my application stops unexpectedly. When I debug, I get a RuntimeExeption before I get to the SharedPreferences [...] code. This is what the Debug window says: DalvikVM[localhost:8609] Thread [3 main] (Suspended (exception RuntimeException)) ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord) line: 2194 ActivityThread.handleLaunchActivity(ActivityThread$ActivityRecord) line: 2284 ActivityThread.access$1800(ActivityThread, ActivityThread $ActivityRecord) line: 112 ActivityThread$H.handleMessage(Message) line: 1692 ActivityThread$H(Handler).dispatchMessage(Message) line: 99 Looper.loop() line: 123 ActivityThread.main(String[]) line: 3948 Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method] Method.invoke(Object, Object...) line: 521 ZygoteInit$MethodAndArgsCaller.run() line: 782 ZygoteInit.main(String[]) line: 540 NativeStart.main(String[]) line: not available [native method] Thread [13 Binder Thread #2] (Running) Thread [11 Binder Thread #1] (Running) //Kaloer On 11 Maj, 19:52, Cass Surek cass.su...@gmail.com wrote: You could get the context by calling getBaseContext(). Please be more specific on what exactly does not work as your problem might be in another place. Cass On May 11, 5:28 pm, kaloer mkal...@gmail.com wrote: Hi, How do I get the preferences from the preferences.xml file? I have tried with this code: SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences (this); but it does not work. I think the error is coursed by the use of the Context this, because the preferences are set by an other class. How can I access this preferences? Thank you, //Kaloer --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: Get preferences from xml/preferences.xml
Yeah, thank you very much! It works now. I simply made a method like yours in the main method.. //Kaloer On 11 Maj, 22:43, Cass Surek cass.su...@gmail.com wrote: I had to roll back to version 1.1 due to not being able to use the emulator with sensors, but this works fine for me : private void getPrefs(){ SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); this.prefsAudioEnabled = sharedPref.getBoolean (audio_enabled, true); } Placed within the main activity of my application. What is right before the call to the prefs? That could be the culprit. Cass On May 11, 7:18 pm, kaloer mkal...@gmail.com wrote: Hi, thank for your help, I have tried the getBaseContext() method, but I get my application stops unexpectedly. When I debug, I get a RuntimeExeption before I get to the SharedPreferences [...] code. This is what the Debug window says: DalvikVM[localhost:8609] Thread [3 main] (Suspended (exception RuntimeException)) ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord) line: 2194 ActivityThread.handleLaunchActivity(ActivityThread$ActivityRecord) line: 2284 ActivityThread.access$1800(ActivityThread, ActivityThread $ActivityRecord) line: 112 ActivityThread$H.handleMessage(Message) line: 1692 ActivityThread$H(Handler).dispatchMessage(Message) line: 99 Looper.loop() line: 123 ActivityThread.main(String[]) line: 3948 Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method] Method.invoke(Object, Object...) line: 521 ZygoteInit$MethodAndArgsCaller.run() line: 782 ZygoteInit.main(String[]) line: 540 NativeStart.main(String[]) line: not available [native method] Thread [13 Binder Thread #2] (Running) Thread [11 Binder Thread #1] (Running) //Kaloer On 11 Maj, 19:52, Cass Surek cass.su...@gmail.com wrote: You could get the context by calling getBaseContext(). Please be more specific on what exactly does not work as your problem might be in another place. Cass On May 11, 5:28 pm, kaloer mkal...@gmail.com wrote: Hi, How do I get the preferences from the preferences.xml file? I have tried with this code: SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences (this); but it does not work. I think the error is coursed by the use of the Context this, because the preferences are set by an other class. How can I access this preferences? Thank you, //Kaloer --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: Get preferences from xml/preferences.xml
Glad to be of help. Good luck. :) Cass On May 11, 9:59 pm, kaloer mkal...@gmail.com wrote: Yeah, thank you very much! It works now. I simply made a method like yours in the main method.. //Kaloer On 11 Maj, 22:43, Cass Surek cass.su...@gmail.com wrote: I had to roll back to version 1.1 due to not being able to use the emulator with sensors, but this works fine for me : private void getPrefs(){ SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); this.prefsAudioEnabled = sharedPref.getBoolean (audio_enabled, true); } Placed within the main activity of my application. What is right before the call to the prefs? That could be the culprit. Cass On May 11, 7:18 pm, kaloer mkal...@gmail.com wrote: Hi, thank for your help, I have tried the getBaseContext() method, but I get my application stops unexpectedly. When I debug, I get a RuntimeExeption before I get to the SharedPreferences [...] code. This is what the Debug window says: DalvikVM[localhost:8609] Thread [3 main] (Suspended (exception RuntimeException)) ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord) line: 2194 ActivityThread.handleLaunchActivity(ActivityThread$ActivityRecord) line: 2284 ActivityThread.access$1800(ActivityThread, ActivityThread $ActivityRecord) line: 112 ActivityThread$H.handleMessage(Message) line: 1692 ActivityThread$H(Handler).dispatchMessage(Message) line: 99 Looper.loop() line: 123 ActivityThread.main(String[]) line: 3948 Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method] Method.invoke(Object, Object...) line: 521 ZygoteInit$MethodAndArgsCaller.run() line: 782 ZygoteInit.main(String[]) line: 540 NativeStart.main(String[]) line: not available [native method] Thread [13 Binder Thread #2] (Running) Thread [11 Binder Thread #1] (Running) //Kaloer On 11 Maj, 19:52, Cass Surek cass.su...@gmail.com wrote: You could get the context by calling getBaseContext(). Please be more specific on what exactly does not work as your problem might be in another place. Cass On May 11, 5:28 pm, kaloer mkal...@gmail.com wrote: Hi, How do I get the preferences from the preferences.xml file? I have tried with this code: SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences (this); but it does not work. I think the error is coursed by the use of the Context this, because the preferences are set by an other class. How can I access this preferences? Thank you, //Kaloer --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---