How to start new activity on button click

后端 未结 24 1668
傲寒
傲寒 2020-11-21 05:54

In an Android application, how do you start a new activity (GUI) when a button in another activity is clicked, and how do you pass data between these two activities?

24条回答
  •  一整个雨季
    2020-11-21 06:38

    Emmanuel,

    I think the extra info should be put before starting the activity otherwise the data won't be available yet if you're accessing it in the onCreate method of NextActivity.

    Intent myIntent = new Intent(CurrentActivity.this, NextActivity.class);
    
    myIntent.putExtra("key", value);
    
    CurrentActivity.this.startActivity(myIntent);
    

提交回复
热议问题