SharedPreferences bug when writing strings with ampersands in them

by cmgreen...@googlemail.com » Sat, 07 Mar 2009 10:54:16 GMT


Sponsored Links
 Hi All,

I've just tracked down a weird bug in our app where SharedPreferences
were failing between power cycles of the phone.

It turns out that one of the strings we were saving had an "&" in it.
When I look at the xml that is being persisted I see that this is
being encoded as && instead of just &

This means that when you come to read the settings back you don't get
any values at all.

Is this a known issue? I see lots of posts about preferences
dissappearing, but nothing about this.

Cheers
Chris.

--~--~---------~--~----~------------~-------~--~----~



SharedPreferences bug when writing strings with ampersands in them

by Mark Murphy » Sat, 07 Mar 2009 23:09:14 GMT


 


Well, you posted an issue, so it's known now!

;-)

However, if you could attach some sample code to that issue that
demonstrates the bug, that may help get it resolved more quickly.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com 
_The Busy Coder's Guide to Android Development_ Version 2.0 Published!

--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Other Threads

1. Putting Views on top of other views.

I'm still trying to figure out how best to layer views on top of other
views. I want to do something like the ZoomButtons on top of a custom
view. I tried getting the ZoomButtonsController's parent and then
adding views, but I didn't have enough control and they ended up on
top of the buttons.

I've gotten close by using a FrameLayout and some gravity on the top
two views. But this has some interesting effects. Since this is
contained with a tab, these two top views appear on top of all four of
the tab pages. I want them on top of one of those pages only.
Apparently, nested FrameLayouts don't mix well.

What is the proper and expected way to do this?

Here is more or less my complete layout, in case that helps.

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@android:id/tabhost" android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <LinearLayout android:orientation="vertical"
                android:layout_width="fill_parent"
android:layout_height="fill_parent">
                <TabWidget android:id="@android:id/tabs"
                        android:layout_width="fill_parent"
android:layout_height="wrap_content" />
                <FrameLayout android:id="@android:id/tabcontent"
                        android:layout_width="fill_parent"
android:layout_height="fill_parent">
                        <LinearLayout android:id="@+id/map_panel"
                                android:orientation="vertical" 
android:layout_width="fill_parent"
                                android:layout_height="fill_parent">
                                >
                                <FrameLayout android:layout_width="fill_parent"
                                        android:layout_height="fill_parent">

                                        <MyCustomView
                                                android:id="@+id/view_map" 
android:layout_width="fill_parent"
                                                
android:layout_height="fill_parent" />
                                        <TextView
                                                android:id="@+id/text_cr" 
android:layout_width="wrap_content"
                                                
android:layout_height="wrap_content" android:textColor="@color/
copyright_link"
                                                android:gravity="top|right" 
android:text=""
android:textSize="20sp"
                                                
android:layout_gravity="top|right">

                                        </TextView>
                                        <SeekBar android:id="@+id/s_bar"
android:layout_width="fill_parent"
                                        android:layout_height="wrap_content" 
android:max="20"
                                        android:progress="9" 
android:secondaryProgress="14"
                                        android:layout_gravity="bottom"/>

                                </FrameLayout>

                        </LinearLayout>
                    <LinearLayout android:id="@+id/view_two"
                        android:orientation="vertical"
                        android:background="@drawable/red"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        >

                                <MySecondCustomView 
android:id="@+id/view_customtwo"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_weight="0.5"/>

                        <ListView android:id="@+id/list_facts"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_weight="0.5"/>
                        </LinearLayout>


                        <TextView android:id="@+id/view_three"
                        android:background="@drawable/green"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        android:text="@string/tab_three"/>

                    <TextView android:id="@+id/view_four"
                        android:background="@drawable/yellow"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        android:text="@string/tab_four"/>
        </FrameLayout>
    </LinearLayout>
</TabHost>


Thanks

Nathan

-- 

2. Media Player Issues With Song ID's

I'm making a basic media player that uses a cursor to query the
playlist members. It does everything fine, but I cannot figure out how
to play a song once I have it in a cursor.

        mSongList =
Uri.withAppendedPath(ContentUris.withAppendedId(Playlists.EXTERNAL_URI,
playlistId), Members.CONTENT_DIRECTORY);
        songsCursor = getContentResolver().query(mSongList, null,
null, null, null);
        mSongId = songsCursor.getColumnIndex(Members.AUDIO_ID);
        columnTitle = songsCursor.getColumnIndex(Members.TITLE);
        columnArtist = songsCursor.getColumnIndex(Members.ARTIST);
        int id = songsCursor.getColumnIndex(Members._ID);

        mp = new MediaPlayer();
        while(mSongsLeft >= 0)
        {
                nextSong();

                ////    THIS IS WRONG     ??????
                mSong = ContentUris.withAppendedId(mPlaylists,
songsCursor.getInt(mSongId));
                //////

                try
                {
                        mp.setDataSource(this, mSong);
                        mp.start();

I just need the code to convert it into a proper uri or just get the
path...

-- 

3. Play time

4. how to access MTP library through Android ?

5. Showing Custom Dialog

6. Catching and changing a keycode.

7. Alternate GPS aplikas