I am having some trouble with implementing my own observer in Java on the Android platform.
I have created a class call NetworkPathJni that uses an Observer interface class called NetworkPathJniObserver to notify other objects of changes. Here is the code for NetworkPathJni.java --- public class NetworkPathJni { NetworkPathJniObserver networkPathJniObserver; public NetworkPathJni(NetworkPathJniObserver aObserver){ networkPathJniObserver = aObserver; Log.d("Phone", "NetworkPathJni Created" ); } public void NetworkPathStateChanged(int aAvailabilityState){ Log.d("Phone", "NetworkPathStateChanged new state = " + aAvailabilityState ); TAvailabilityState availabilityState = intToAvailability(aAvailabilityState); Log.d("Phone", "Is SipNetworkPath alive?" + networkPathJniObserver.isAlive()); networkPathJniObserver.NetworkPathStateChanged(availabilityState); Log.d("Phone", "NetworkPathStateChanged end" ); Log.d("Phone", "Is SipNetworkPath alive? (2)" + networkPathJniObserver.isAlive()); } --- And here is the code for the observer --- public interface NetworkPathJniObserver { void NetworkPathStateChanged(TAvailabilityState aAvailabilityState); boolean isAlive(); } --- The observer is implemented as follows in a class called SipNetworkPath --- public class SipNetworkPath implements NetworkPathInterface, NetworkPathJniObserver{ NetworkPathObserverInterface observer; NetworkPathJni networkPathJni; public SipNetworkPath(NetworkPathObserverInterface aObserver){ domainType = aDomainType; observer = aObserver; networkPathJni = new NetworkPathJni(this); Log.d("Phone", "SipNetworkPath created" ); } //NetworkPathJniObserver @Override public void NetworkPathStateChanged(TAvailabilityState availabilityState) { Log.d("SipNetworkPath", "SipNetworkPath - Do networkpathstate changed!"); } @Override public boolean isAlive() { return true; } --- And SipNetworkPath is instanciated as follows --- public class WifiNetworkPath extends SipNetworkPath{ public WifiNetworkPath(NetworkPathObserverInterface aObserver) { super(aObserver); } --- The logging shows that both NetworkPathJni and SipNetworkPath get created and that NetworkPathStateChanged(int aAvailabilityState) is called. Within that method all the logging comes back but the method does not get called in the observer and I get false when I ask "Is SipNetworkPath alive?" in the logging. Is the observer class losing reference or something or is there a mistake in my way of doing this? Does Android kill off objects that are not part of an Activity or a Service instantly or something along thoese lines that might be causing the problem? -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en