How to start an Intent by passing some parameters to it?

前端 未结 3 1094
轻奢々
轻奢々 2020-11-28 20:23

I would like to pass some variables in the constructor of my ListActivity

I start activity via this code:

startActivity(new Intent (this, viewConta         


        
3条回答
  •  攒了一身酷
    2020-11-28 21:29

    I think you want something like this:

    Intent foo = new Intent(this, viewContacts.class);
    foo.putExtra("myFirstKey", "myFirstValue");
    foo.putExtra("mySecondKey", "mySecondValue");
    startActivity(foo);
    

    or you can combine them into a bundle first. Corresponding getExtra() routines exist for the other side. See the intent topic in the dev guide for more information.

提交回复
热议问题