Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Android Intents using Dart & Henson

Android Intents using Dart & Henson

Diego Velásquez

August 20, 2017
Tweet

More Decks by Diego Velásquez

Other Decks in Programming

Transcript

  1. Intents An intent is an abstract description of an operation

    to be performed. Activity Broadcast Receiver Service Intent
  2. Have not specified a component; instead declare a general action

    to perform, which allows a component from another app to handle it Intent types Have specified a component which provides the exact class to be run. Implicit Explicit
  3. Creating & Consuming Intents public static final String INTENT_PARAM =

    "param_name"; ... Intent intent = new Intent( this, DetailActivity.class); intent.putExtra(INTENT_PARAM, "Android"); startActivity(intent); public static final String INTENT_PARAM = "param_name"; ... Intent intent = getIntent(); if (intent != null && intent.hasExtra(INTENT_PARAM)){ String name = getIntent().getStringExtra(INTENT_PARAM); }
  4. What do we do? public static void startDetailActivity(Context context, String

    param1, String param2){ Intent intent = new Intent(context, DetailActivity.class); intent.putExtra("PARAM_1", param1); intent.putExtra("PARAM_2",param2); context.startActivity(intent); } public static void startDetailActivity(Context context, String param1){ Intent intent = new Intent(context, DetailActivity.class); intent.putExtra("PARAM_1", param1); context.startActivity(intent); } public static void startDetailActivity(Context context, String param1, String param2){ Intent intent = new Intent(context, DetailActivity.class); if (param1 != null) intent.putExtra("PARAM_1", param1); if (param2 != null) intent.putExtra("PARAM_2",param2); context.startActivity(intent); } public static void startDetailActivity(Context context, String param1){ startDetailActivity(context, param1,null); } Refactoring
  5. Dart: Consuming Intents DetailActivity.java @InjectExtra String paramName; … @Override protected

    void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_detail); Dart.inject(this); }
  6. Dart: Features @InjectExtra String paramName; @InjectExtra User user; @InjectExtra("quantity") int

    quantityValue; @InjectExtra boolean isSuccess = false; @Nullable @InjectExtra String anotherValue; public class DetailModel { @InjectExtra String valueModel; public String getValueModel() { return valueModel; } } DetailActivity.java DetailModel model = new DetailModel(); …. @Override protected void onCreate(Bundle savedInstanceState) { …. Dart.inject(model,this); String ourValue = model.getValueModel(); }
  7. Henson: Creating Intents @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main); Intent intent = Henson.with(this).gotoDetailActivity().paramName("Test value").build(); startActivity(intent); }
  8. Henson: Features Intent intent = Henson.with(this).gotoDetailActivity() .isSuccess(true) .paramName("Test") .quantity(5) .user(new

    User()) .build(); startActivity(intent); @HensonNavigable(model = DetailModel.class) public class DetailActivity extends AppCompatActivity { DetailModel model = new DetailModel(); …. @Override protected void onCreate(Bundle savedInstanceState) { …. Dart.inject(model,this); } Intent intent = Henson.with(this).goToDetailActivity().valueModel("testing").build(); startActivity(intent);