I am using the Observer pattern in my Android application to notify a
running service that some data has changed:

Here is the code outside the Service: (WifiConnectionManager)

---

    //Observables
    @Override
        public void NotifyQCLevelChange(QCLevel newQoSLevel) {
                setChanged();
                notifyObservers( newQoSLevel );
        }


        @Override
        public void NotifyQCPercentageChange(int percentage) {
                setChanged();
                notifyObservers( percentage );
        }

---

Where the observables get updated within an Observer update method:
(WifiConnectionManager)

---

    @Override
        public void update(Observable arg0, Object arg) {
                if( !iActive )
                        return;

                if( arg0 instanceof WifiMonitor ){
                        Log.d("WifiConnectionManager", "update from WiFiMonitor 
ss=:" +
arg.toString());
                        if( iConnectionState.equals(ConnectionState.IPACTIVE) )
                        {
                                int qcPercentage = 
Integer.parseInt(arg.toString());
                                Log.d("GetActiveQCLevel", "GetActiveQCLevel 
called");
                                QCLevel aConnectionQCLevel = 
GetActiveQCLevel(qcPercentage);


                                if( 
!aConnectionQCLevel.equals(iConnectionQCLevel) )
                                {
                                        iConnectionQCLevel = aConnectionQCLevel;
                                        NotifyQCLevelChange(iConnectionQCLevel);
                                        Log.d("NotifyQCLevelChange", 
"NotifyQCLevelChange");
                                }

                                NotifyQCPercentageChange(qcPercentage);
                                Log.d("NotifyQCPercentageChange", 
"NotifyQCPercentageChange");
                        }
                }

---

And finally the Observer in my service: (WifiService)

---

        @Override
        public void update(Observable observable, Object data) {

                if( observable instanceof WifiConnectionManager && data 
instanceof
QCLevel){

                        Log.d("WifiConnectionManager", "instanceof QCLevel");

                }
                else if( observable instanceof WifiConnectionManager && data
instanceof Integer){

                        Log.d("WifiConnectionManager", "instanceof Integer");

                }
                else if( observable instanceof WifiConnectionManager){

                        Log.d("WifiConnectionManager", "instanceof 
WifiConnectionManager");

                }

---

>From the log I can see that Log.d("GetActiveQCLevel",
"GetActiveQCLevel called"); &&
Log.d("NotifyQCPercentageChange", "NotifyQCPercentageChange"); get
called but nothing in the update method of the Observer in my service
(WifiService) gets called.

Can anyone see where the problem is or is there a restriction I am not
aware of?

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to