Anonymous Anonymous - 9 days ago
135 0

No description

Java

Stackoverflow - listener null

//// First activity
Main Activity {


    // Reference to second activity
private IntroActivity mIntroActivity;

@Override
protected void onCreate(Bundle savedInstanceState) {

  Intent i = new Intent(MainActivity.this, IntroActivity.class);
startActivity(i);


    /// Call back for second activity
  mIntroActivity.setIntroListener(new IntroActivity.IntroListener() {
      @Override
      public void finished() {
        /// When finished do something!
      }

  });

}
}


/// Second Activity

public class IntroActivity extends AppIntro {

    /// Listener setup

  public interface IntroListener {
      void finished();
  }


  public void setIntroListener(IntroListener listener) {
      this.mIntroListen = listener;
  }

  public IntroActivity(){
      this.mIntroListen = null;
  }


  private IntroListener mIntroListen;



    @Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

  }

  @Override
public void onDonePressed(Fragment currentFragment) {
    super.onDonePressed(currentFragment);

    /// Call listenr from MainActivity
    mIntroListen.finished();
}



}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download