evant / loadie

Android Loaders for the rest of us
Apache License 2.0
14 stars 1 forks source link

Some way to pass args to loader. #1

Open evant opened 8 years ago

evant commented 8 years ago

For example, on signin, you'd want to pass a username and password to Loader#restart()

evant commented 8 years ago

Option 1

A single generic type param.

public class MyLoader extends Loader<Arg, Result> {
  @Override
  protected void onStart(Arg arg, Receiver receiver) { ... }
}

Arg arg = ...;
myLoader.start(arg);

pros:

cons:

Option 2

A vararg Object param.

public class MyLoader extends Loader<Result> {
  @Override
  protected void onStart(Object[] args, Receiver receiver) { ... }
}

Arg arg = ...;
myLoader.start(arg);

pros:

cons:

Option 3

A Bundle param.

```java
public class MyLoader extends Loader<Result> {
  @Override
  protected void onStart(Bundle args, Receiver receiver) { ... }
}

Arg arg = ...;
Bundle args = new Bundle();
args.putParcelable("arg", arg);
myLoader.start(args);

pros:

cons:

ersin-ertan commented 7 years ago

I'm liking option 1, some of my networking calls using retrofit use @Post , having a single @Body LoginUserobject holding the credentials, so this pattern is familiar.