i am implementing one game application in this application i am using shared preferences in preferences Activity
spinnerTheme.setOnItemSelectedListener(new OnItemSelectedListener(){
SharedPreferences prefs1 = getSharedPreferences("TipCalcPreferenceDatabase", 0);
Editor e = prefs1.edit();
public void onItemSelected(AdapterView parent,View v,int position,long id)
{
prefs = getSharedPreferences("TipCalcPreferenceDatabase", 0);
Editor e = prefs.edit();
String str;
if(position==0)
{
str= String.valueOf((R.drawable.image1));
e.putString("TipCalcPropertyName", str);
}
if(position==1)
{
str= String.valueOf((R.drawable.image2));
e.putString("TipCalcPropertyName", str);
}
else if(position==2)
{
str= String.valueOf((R.drawable.ballon_background));
e.putString("TipCalcPropertyName", str);
}
e.commit();
/* Preferences current Theme update START*/
String mySetting = prefs.getString("TipCalcPropertyName", "");
LinearLayout ln=(LinearLayout) findViewById(R.id.LinearLayout);
ln.setBackgroundResource((int) Double.parseDouble(mySetting) );
}
public void onNothingSelected(AdapterView<?> arg0)
{
// TODO Auto-generated method stub
}
});
above sharedprefrences how can implementing in surface view class
this is the surface class initialize() abstract method extends to layout class
public void initialize()
{
int n;
Bitmap background;
// Screen size
Log.v("height",scwidth+"is width and height is "+scheight);
background=getImage(R.drawable.image1);
background = background.createScaledBitmap(background,scwidth,scheight, true);
}
below xml file is surface view
<com.softwares.bird.BirdGame xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ll_absolute"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FF000000" android:orientation="horizontal">
</com.softwares.bird.BirdGame>
this shared prefrences values how can pass surface view class
forward valuable suggestion i am struck in this issue in more days
thanks in advance
I actually had this issue and since my application wants to store a more complex object I did this I took the object serialized it then stored it to a file. I can then check from any activity this file and get the full object. No need to use the string key garbage of prefs and Bundles.
You will need this to serialize and deserialize:
and finally you need to create global object state you can reference.
Oh yeah and you need to update your AndroidManifest.xml file to include the reference to the ObjectState since it references Application like this…