Constants/user defined attributes in Resouce xml

Put your problem here if it does not fit any of the other categories.

Constants/user defined attributes in Resouce xml

Postby manmath » Thu Feb 28, 2008 7:15 am

Hi All,

I want to store constants/user defined attributes (like Phone type, build version etc) as xml. My requirement is to store it as key-value pair as we store in JAD files in J2me. I guess string.xml is an option. Is there any other way to store these values as xml?

thanks
Manmath :roll:
manmath
Junior Developer
Junior Developer
 
Posts: 18
Joined: Fri Feb 15, 2008 1:30 pm
Location: India

Top

Postby plusminus » Thu Feb 28, 2008 9:47 am

Hello manmath,

Files under "/res/raw/" do not got compiled and can be accessed "as they are":
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. InputStream is = getResources().openRawResource(id);
Parsed in 0.029 seconds, using GeSHi 1.0.8.4


If XML is no explicit need, you could also use (Shared)Preferences to save Key/Value-Pairs.

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby manmath » Thu Feb 28, 2008 11:15 am

Hi plusminus,

Thanks a lot for your Reply.
Now I am trying with shared preference. I have some design issues.

:arrow: 1. I am not able to acess outside the package<which contains main Activity>. It shows stack overflow error in runtime. Is there any option i can access outside the application package ?

:arrow: 2. How can I edit the <prefs.xml> in adb shell ? I am able to see the file and shared preference values using cat command. what is the command to edit the file? " vi" is not working in the shell.

Regards
Manmath
manmath
Junior Developer
Junior Developer
 
Posts: 18
Joined: Fri Feb 15, 2008 1:30 pm
Location: India

Postby plusminus » Thu Feb 28, 2008 12:39 pm

Hello manmath,

1. it works fine with me. I.e. I'm saving the the id of the overall application theme. (Called from Activites placed in different packages):
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         /** Applies the theme saved in Preferences to the Activity parameter.
  2.  
  3.          * @param act Activity to set the shared theme to. */
  4.  
  5.         public static void applySharedTheme(Activity act){
  6.  
  7.                 SharedPreferences sPref = act.getSharedPreferences(Constants.SHARED_PREFERENCES_NAME, ApplicationContext.MODE_PRIVATE);
  8.  
  9.                 int themeID = sPref.getInt(Constants.PREF_THEME_RESID_ID, Constants.DEFAULT_THEME_RESID);
  10.  
  11.                 act.setTheme(themeID);
  12.  
  13.         }
  14.  
  15.        
  16.  
  17.         /** Returns the theme saved in Preferences to the Activity parameter.
  18.  
  19.          *      @param act Activity needed to retrieve the SharedPreferences. */
  20.  
  21.         public static int getSharedThemeID(Activity act){
  22.  
  23.                 SharedPreferences sPref = act.getSharedPreferences(Constants.SHARED_PREFERENCES_NAME, ApplicationContext.MODE_PRIVATE);
  24.  
  25.                 return sPref.getInt(Constants.PREF_THEME_RESID_ID, Constants.DEFAULT_THEME_RESID);
  26.  
  27.         }
  28.  
  29.        
  30.  
  31.         /** Save a sharedThemeID to be used by the whole application.
  32.  
  33.          * @param act Activity needed to retrieve the SharedPreferences.
  34.  
  35.          * @param aThemeID ThemeID to be saved and used by the whole application. */
  36.  
  37.         public static void saveSharedThemeID(Activity act, int aThemeID){
  38.  
  39.                 SharedPreferences sPref = act.getSharedPreferences(Constants.SHARED_PREFERENCES_NAME, ApplicationContext.MODE_PRIVATE);        
  40.  
  41.                 SharedPreferences.Editor editor = sPref.edit();
  42.  
  43.                
  44.  
  45.                 editor.putInt(Constants.PREF_THEME_RESID_ID, aThemeID);
  46.  
  47.                 editor.commit();
  48.  
  49.         }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


2. Sorry, I'm not working with Console.

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby manmath » Fri Feb 29, 2008 7:37 am

Thanks a lot plusminus.
manmath
Junior Developer
Junior Developer
 
Posts: 18
Joined: Fri Feb 15, 2008 1:30 pm
Location: India

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 11 guests