Skip to content
This repository has been archived by the owner on May 15, 2023. It is now read-only.

Consider scheduling VariableMethods on the next event loop from RemixerBinder.bind(this) #86

Open
pingpongboss opened this issue Nov 21, 2016 · 0 comments

Comments

@pingpongboss
Copy link
Contributor

I have code like this:

  private View target;

  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main_activity);

    RemixerBinder.bind(this); // [1]
    RemixerFragment remixerFragment = RemixerFragment.newInstance();
    remixerFragment.attachToButton(this, (Button) findViewById(R.id.remixer_button));

    target = findViewById(R.id.target); // [3]
  }

  @BooleanVariableMethod(defaultValue = true)
  public void setFoo(Boolean foo) {
    target.bar(); // [2]
  }

This throws a NullPointerException at [2].

In this simple example, [1] is called first, which synchronously calls [2]. This is a problem because [3] has not yet run.

One solution is to teach clients to perform all dependent initializations before RemixerBinder.bind(this). This has the problem of education and that it's not always obvious what is a dependent initialization and what can happen later.

An alternative solution is for RemixerBinder.bind(this) to schedule (Activity#runOnUiThread, Handler#post) the VariableMethods to run on the next event loop iteration, giving onCreate() a chance to finish.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant