Consider an Activity
you would like to start, ExampleActivity
:
public class ExampleActivity extends AppCompatActivity {
ExampleActivity
may have a few parameters it receives from another Activity
:
private int numberToDisplay // This param is required for ExampleActivity to start successfully!
private String stringToDisplay
private DataModel dataModel; // Parcelable or Serializable
With Piri, you can generate an Intent builder for ExampleActivity
, and it only requires a few annotations.
public class ExampleActivity extends AppCompatActivity {
@PiriParam(required = true)
protected int numberToDisplay;
@PiriParam
protected String stringToDisplay;
@PiriParam
protected DataModel dataModel;
...
Okay cool! But how do we use it?
When you build your project, a class called ExampleActivityIntentCreator
will be generated:
// number gets created as a constructor param due to being required
Intent intent = new ExampleActivityIntentCreator(context, number)
.stringToDisplay(string)
.dataModel(dataModel)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK, Intent.FLAG_ACTIVITY_NEW_TASK)
.create();
startActivity(intent);
Easy! You can then retrieve your data when ExampleActivity
is started with Piri.bind()
:
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_example);
Piri.bind(this)
// Defined PiriParam variables are set for you
...