pass values from one screen to another?

后端 未结 3 1855
失恋的感觉
失恋的感觉 2021-01-25 05:16

I need to pass data\'s (String) from one screen to another screen. At the time of button click i need to pass values from first screen to the next screen.

3条回答
  •  终归单人心
    2021-01-25 05:29

    You can pass along data as extras in the intent that starts the second activity:

    Intent myIntent = new Intent(view.getContext(), NextActivity.class); 
    myIntent.putExtra("extra", id);
    startActivityForResult(myIntent, 0);   
    

    In the oncreate method of your profile activity you can access the extras:

    int id = getIntent().getStringExtra("extra");       
    

    If you are new to Android, it might help to read through the examples in the developer docs, like the notepad tutorial.

提交回复
热议问题