How do I create an android Intent that carries data?

前端 未结 3 819
梦谈多话
梦谈多话 2020-12-02 01:45

I might have misunderstood how intents are supposed to be used, so I might be asking the wrong thing here. If that\'s the case, please help me get on the right track with th

3条回答
  •  一整个雨季
    2020-12-02 02:10

    You can do the following to add information into the intent bundle:

        Intent i = new Intent(MessageService.this, ViewMessageActivity.class);
        i.putExtra("message", "value");
        startActivity(i);
    

    Then in the activity you can retrieve like this:

        Bundle extras = getIntent().getExtras();
        String message = extras.getString("message");
    

提交回复
热议问题