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

Grenade - Type safe intent buidler

Grenade - Type safe intent buidler

potatotips 34

Keisuke Kobayashi

October 26, 2016
Tweet

More Decks by Keisuke Kobayashi

Other Decks in Programming

Transcript

  1. XJUIFYUSB Intent intent = new Intent(context, HogeActivity.class); intent.putExtra("name", "Takashi"); intent.putExtra("age",

    30); startActivity(intent); String name = getIntent().getStringExtra("name"); int age = getIntent().getIntExtra("age", 0);
  2. XJUIFYUSB Intent intent = new Intent(context, HogeActivity.class); intent.putExtra("name", "Takashi"); intent.putExtra("age",

    30); startActivity(intent); String name = getIntent().getStringExtra("name"); int age = getIntent().getIntExtra("age", 0); w ͍ΖΜͳը໘ʹఆ਺͕ग़ͯདྷΔ
  3. XJUIFYUSB Intent intent = new Intent(context, HogeActivity.class); intent.putExtra("name", "Takashi"); intent.putExtra("age",

    30); startActivity(intent); String name = getIntent().getStringExtra("name"); int age = getIntent().getIntExtra("age", 0); w ͍ΖΜͳը໘ʹఆ਺͕ग़ͯདྷΔ w ม਺Λ٧Ί๨Εͯ΋ίϯύΠϧΤϥʔग़ͳ͍
  4. TUBUJDNFUIPE static void startActivity(Context context, String name, int age) {

    Intent intent = new Intent(context, HogeActivity.class); intent.putExtra(KEY_NAME, "Takashi"); intent.putExtra(KEY_AGE, 30); context.startActivity(intent); } String name = getIntent().getStringExtra(KEY_NAME); int age = getIntent().getIntExtra(KEY_AGE, 0);
  5. 6TBHF @Navigator public class DetailActivity extends AppCompatActivity { // Required

    params @Extra String name; // Optional params @Extra @Optional int age; ... }
  6. 6TBHF @Navigator public class DetailActivity extends AppCompatActivity { ... @Override

    protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Inject fields DetailActivityNavigator.inject(this, getIntent()); } }