How do I get extra data from intent on Android?

后端 未结 16 2709
清歌不尽
清歌不尽 2020-11-21 11:01

How can I send data from one activity (intent) to another?

I use this code to send data:

Intent i=new Intent(context,SendMessage.class);
i.putExtra(\         


        
16条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-21 12:00

    You can also do like this
    // put value in intent

        Intent in = new Intent(MainActivity.this, Booked.class);
        in.putExtra("filter", "Booked");
        startActivity(in);
    

    // get value from intent

        Intent intent = getIntent();
        Bundle bundle = intent.getExtras();
        String filter = bundle.getString("filter");
    

提交回复
热议问题