Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 920933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:47:47+00:00 2026-05-15T18:47:47+00:00

I am having some trouble with implementing my own observer in Java on the

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T18:47:48+00:00Added an answer on May 15, 2026 at 6:47 pm

    In method NetworkPathStateChanged you’re doing nothing with the availability state. Usually you would store it internally, like this:

    private TAvailabilityState availablilityState = null; // or a more suiteable initial value
    @Override
    public void NetworkPathStateChanged(TAvailabilityState availabilityState) {
        this.availabilityState = availabilityState;
        Log.d("SipNetworkPath", "SipNetworkPath - Do networkpathstate changed!");
    }
    

    Then, in method isAlive you would respond based on the state:

    @Override
    public boolean isAlive() {
        return availabilityState == TAvailabilityState.ALIVE; // <-- this is just a guess, I don't know this class or enum.  
    }
    

    In this case (referring to your comment) another implementation of NetworkPathJniObserver must exist somewhere or you still have an old class file on the classpath. Just because: if an isAlive() method returns false while the one in the source code can’t, then there must be some other code in your application.

    I’d add some debug code to the method to clearly log which instances are actually called. (My guess would be, that the last compiled version(s) hasn’t been deployed…)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 465k
  • Answers 465k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You could solve this by having a class which all… May 16, 2026 at 1:15 am
  • Editorial Team
    Editorial Team added an answer What gets post back from a form in MVC is… May 16, 2026 at 1:15 am
  • Editorial Team
    Editorial Team added an answer You also need a CFBundleDocumentTypes declaration. <key>CFBundleDocumentTypes</key> <array> <dict> <key>CFBundleTypeIconFile</key>… May 16, 2026 at 1:15 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.