OnSharedPreferenceChangeListener never receives callback

by Mark Murphy » Wed, 16 Jun 2010 04:29:32 GMT


Sponsored Links
 


It shouldn't be. It works in services, and services never have the focus.


Try using "this" instead of "getApplicationContext()"

-- 
Mark Murphy
CommonsWare
mmur...@commonsware.com
 http://commonsware.com 

--



OnSharedPreferenceChangeListener never receives callback

by Connick » Wed, 16 Jun 2010 04:40:32 GMT


 No effect. I'm registering the listener in onCreate of my activity, not sure
if that has any implications. I've also been assuming this should fire when
prefs are either changed via a pref activity and/or when a commit is called
from a shared pref editor?

-Stace







>


Sponsored Links


OnSharedPreferenceChangeListener never receives callback

by Mark Murphy » Wed, 16 Jun 2010 04:42:42 GMT


 


Correct.

-- 
Mark Murphy
CommonsWare
mmur...@commonsware.com
 http://commonsware.com 

--



OnSharedPreferenceChangeListener never receives callback

by Connick » Wed, 16 Jun 2010 04:43:05 GMT


 Interesting, it only works if used within an activity that extends
PreferenceActivity. Crap.







>>



OnSharedPreferenceChangeListener never receives callback

by Mark Murphy » Wed, 16 Jun 2010 04:46:40 GMT


 


So long as all components are using the same preference file, it
should work for modifications from any source. That is what I meant by
"correct" in my previous reply.

-- 
Mark Murphy
CommonsWare
mmur...@commonsware.com
 http://commonsware.com 

--



OnSharedPreferenceChangeListener never receives callback

by Connick » Wed, 16 Jun 2010 05:18:50 GMT


 Will file a big, thx!






>



OnSharedPreferenceChangeListener never receives callback

by Connick » Wed, 16 Jun 2010 05:53:13 GMT


 Cancel that, I just grasped what you were getting at. :)







>>



Other Threads

1. Sense UI

Sorry if this is a duplicate post (can't find my old one). I was
wondering if anyone knew wether or not the new HTC Sense UI would be
made available for developers to run on the developme G1?

thanks.

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

2. Remote Interface - Parcelables problem...

Been using remote interfaces for quite a while now, but the time has
come to increase the amount of data i need to pass between processes.
Following the Designing a Remote Interface using aidl examples/
tutorial i have had some success but have now come to a problem.

My activity binds to my service no problem, the callbacks work, but
the data i send does not reach the client. My code is an extension of
"Pass by value Parameters using Parcelables" from the  "Designing a
Remote Interface using aidl" page. The only difference is the amount
of data, it has 18 int's and 3 Doubles. As you will see below, once i
have entered the data into the parcel, i create my Parcelable
using .createFromParcel(p) this however does not seem to work, even
when my Parcelable is reading from the parcel no data gets read.

Here is my code for sending the data to the client.

/*
     * Send the latest info to the bound apps
 */
    private void updateBoundApps(){

        if(mCallbacks.beginBroadcast() > 0){
                if(gLOG){Log.d(TAG,"updateBoundApps " + mSMNI.int1);} // Always
shows int1 as corret value (non 0)

                Parcel p = Parcel.obtain();
                p.writeInt(mSMNI.int1);
                p.writeInt(mSMNI.int2);
                p.writeInt(mSMNI.int3);
                p.writeInt(mSMNI.int4);
                p.writeInt(mSMNI.int5);
                p.writeInt(mSMNI.int6);

                Iterator<Entry<Object, Object>> itNew = mSMNI.intMap.entrySet
().iterator();
                for(int i = 0 ; i < 6; i++){
                        if(itNew.hasNext()){
                                Map.Entry<Object, Object> eNew = itNew.next();
                                p.writeInt((Integer) eNew.getKey());
                                p.writeInt((Integer) eNew.getValue());
                        }else{
                                p.writeInt(0);
                                p.writeInt(0);
                        }
                }
                p.writeDouble(mLastLoc.Double1);
                p.writeDouble(mLastLoc.Double2);
                p.writeDouble(mLastLoc.Double3);

            MPSData mpsd = MPSData.CREATOR.createFromParcel(p);
            // Send the message
            Message msg = mHandler.obtainMessage(REPORT_MSG, mpsd);
            mHandler.sendMessageDelayed(msg, 1*1000);
            p.recycle();
        }
        mCallbacks.finishBroadcast();
    }

Here is my Parecelable:

public class MPSData implements Parcelable{

        public int int1;
        public int int2;
        public int int3;
        public int int4;
        public int int5;
        public int int6;
        public int int7;
        public int int8;
        public int int9;
        public int int10;
        public int int11;
        public int int12;
        public int int13;
        public int int14;
        public int int15;
        public int int16;
        public int int17;
        public int int18;
        public double double1;
        public double double2;
        public double double3;

        public static final Parcelable.Creator<MPSData> CREATOR = new
Parcelable.Creator<MPSData>() {
                @Override
        public MPSData createFromParcel(Parcel in) {
                        Log.d("MPSData","createFromParcel dataAvail " + 
in.dataAvail() + "
dataSize " + in.dataSize());
            return new MPSData(in);
        }

        public MPSData[] newArray(int size) {
            return new MPSData[size];
        }
    };

    public MPSData(){

    }

        private MPSData(Parcel in){
                Log.d("MPSData","MPSData(Parcel in)");
                readFromParcel(in);
        }

        @Override
        public int describeContents() {
                // TODO Auto-generated method stub
                return 0;
        }

        public void writeToParcel(Parcel out) {
                out.writeInt(int1);
                out.writeInt(int2);
                out.writeInt(int3);
                out.writeInt(int4);
                out.writeInt(int5);
                out.writeInt(int6);
                out.writeInt(int7);
                out.writeInt(int8);
                out.writeInt(int9);
                out.writeInt(int10);
                out.writeInt(int11);
                out.writeInt(int12);
                out.writeInt(int13);
                out.writeInt(int14);
                out.writeInt(int15);
                out.writeInt(int16);
                out.writeInt(int17);
                out.writeInt(int18);
                out.writeDouble(double1);
                out.writeDouble(double2);
                out.writeDouble(double3);
        }

        public void readFromParcel(Parcel in) {
                int1= in.readInt();
                Log.d("MPSData","readFromParcel(Parcel in) " + int1); // Always
shows int1 as 0
                int2= in.readInt();
                int3= in.readInt();
                int4= in.readInt();
                int5= in.readInt();
                int6= in.readInt();
                int7= in.readInt();
                int8= in.readInt();
                int9= in.readInt();
                int10= in.readInt();
                int11= in.readInt();
                int12= in.readInt();
                int13= in.readInt();
                int14= in.readInt();
                int15= in.readInt();
                int16= in.readInt();
                int17= in.readInt();
                int18= in.readInt();
                double1= in.readDouble();
                double2 = in.readDouble();
                double3 = in.readDouble();
    }

        @Override
        public void writeToParcel(Parcel dest, int flags) {
                // TODO Auto-generated method stub

        }

}

Thanks for any help;

Liam

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

3. using tesseract on android

4. Accessing SharedPreferences in Services and non-Activities

5. Get active context dynamically of an application

6. How can I get Activity object from Intent object or something else

7. slider keyboard open detection