Re: [android-developers] Loading and Saving Settings to a file
On Mon, Feb 6, 2012 at 11:15 AM, John-Marc Desmarais j...@ieee.org wrote: I have an Override on onPause to save settings to a file Why not just use SharedPreferences? Can anyone provide insight into this problem? When you check the file existing, you use the raw file name, not relative to your data directory. Of course, that does not exist, as the file is relative to your data directory. Your subsequent call to openFileInput would likely succeed. - TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago transit tracking app for Android-powered devices -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Loading and Saving Settings to a file
Hi, Thank you for your reply. I have a couple follow up comments/questions related to the responses. I have included these inline. On Mon, Feb 6, 2012 at 12:25 PM, TreKing treking...@gmail.com wrote: On Mon, Feb 6, 2012 at 11:15 AM, John-Marc Desmarais j...@ieee.org wrote: I have an Override on onPause to save settings to a file Why not just use SharedPreferences? I felt it would be quicker to serialize my class into a byte stream than saving each configuration parameter separately and I couldn't find the ability to store a byte stream using SharedPreferences. Can anyone provide insight into this problem? When you check the file existing, you use the raw file name, not relative to your data directory. Of course, that does not exist, as the file is relative to your data directory. Your subsequent call to openFileInput would likely succeed. How do I handle the byte[] settingsBuffer = new byte[(int) inputFile.length]; without opening a File? i.e. How would I figure out in advance the size of the byte buffer I need to receive my file? Or, what path can I append to my open file to allow it to find the settingsFile, or is it not that easy? -jm -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Loading and Saving Settings to a file
On Mon, Feb 6, 2012 at 11:36 AM, John-Marc Desmarais j...@ieee.org wrote: How do I handle the byte[] settingsBuffer = new byte[(int) inputFile.length]; without opening a File? You get the stream of data as the returned value of openFileInput. Then you can then read that into a byte array of the input's length. So your settings buffer would be initialized AFTER you open the input stream, using the stream's length. - TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago transit tracking app for Android-powered devices -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Loading and Saving Settings to a file
On Mon, Feb 6, 2012 at 12:56 PM, TreKing treking...@gmail.com wrote: On Mon, Feb 6, 2012 at 11:36 AM, John-Marc Desmarais j...@ieee.org wrote: How do I handle the byte[] settingsBuffer = new byte[(int) inputFile.length]; without opening a File? You get the stream of data as the returned value of openFileInput. Then you can then read that into a byte array of the input's length. So your settings buffer would be initialized AFTER you open the input stream, using the stream's length. Hi Based on your first response I have tried the following: public void onPause() { super.onPause(); // save configuration settings SharedPreferences.Editor settingsEditor = getSharedPreferences(settingsFile, 0).edit(); settingsEditor.putString(RXConfigurationSettings, Base64.encodeToString(cfg.toSerializedBytes(getBaseContext()), Base64.DEFAULT)); } public void loadSettings() { SharedPreferences settings = getSharedPreferences(settingsFile, 0); if (settings.contains(RXConfiguration)) { cfg = RXConfigurationSettings.fromSerializedBytes(Base64.decode(settings.getString(RXConfigurationSettings, ), Base64.DEFAULT)); } else { Log.e(LogName.className, Input settings not found.); } } And am now getting Input settings not found when closing and reopening my application. -jm -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Loading and Saving Settings to a file
On Mon, Feb 6, 2012 at 12:04 PM, John-Marc Desmarais j...@ieee.org wrote: And am now getting Input settings not found when closing and reopening my application. Read the class overview: http://developer.android.com/reference/android/content/SharedPreferences.Editor.html - TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago transit tracking app for Android-powered devices -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Loading and Saving Settings to a file
Yup. commit() still works as advertised. Thank you, -jm On Mon, Feb 6, 2012 at 1:19 PM, TreKing treking...@gmail.com wrote: On Mon, Feb 6, 2012 at 12:04 PM, John-Marc Desmarais j...@ieee.org wrote: And am now getting Input settings not found when closing and reopening my application. Read the class overview: http://developer.android.com/reference/android/content/SharedPreferences.Editor.html - TreKing - Chicago transit tracking app for Android-powered devices -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en