Skip to content
This repository was archived by the owner on May 15, 2023. It is now read-only.
This repository was 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

@pingpongboss

Description

@pingpongboss

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions