In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains the "click on the button in Android to start another Activity and how to solve the problem of passing values between Activity". The content in the article is simple and clear, and it is easy to learn and understand. now please follow the editor's train of thought to slowly deepen, together to study and learn "click the button in Android to start another Activity and how to solve the problem of passing values between Activity"!
Scene
Click the button in the first Activity to start the second Activity, close the second Activity, and return to the first Activity.
The value is passed to the second Activity in the first Activity, and it is fetched and displayed in the second Activity.
Open the second Activity
Activity value
Realize
Start another Activity
In the click event of the button in the first Activity
Button secondActivityButton = (Button) findViewById (R.id.secondActivity); secondActivityButton.setOnClickListener (new View.OnClickListener () {@ Override public void onClick (View v) {/ / the first parameter is the current Activity; the second parameter is the Activity Intent intent = new Intent (MainActivity.this,SecondActivity.class); startActivity (intent);}})
Then in the click event of the close button in the second Activity
Button closeButton = (Button) findViewById (R.id.closeButton); closeButton.setOnClickListener (new View.OnClickListener () {@ Override public void onClick (View v) {finish ();}})
Start Activity and pass a value
In the first Activity button click event
Button paramActivityButton = (Button) findViewById (R.id.paramActivity); paramActivityButton.setOnClickListener (new View.OnClickListener () {@ Override public void onClick (View v) {Intent intent = new Intent (MainActivity.this, SecondActivity.class); / / data intent.putExtra in the form of multiple key-value pairs ("key", "domineering rogue temperament"); intent.putExtra ("key1", "overbearing programmer"); startActivity (intent);}})
In the button click event in the second Activity
Button valueButton = (Button) findViewById (R.id.valueButton); valueButton.setOnClickListener (new View.OnClickListener () {@ Override public void onClick (View v) {String valueString = (String) getIntent () .getExtras () .get ("key"); String valueString1 = (String) getIntent () .getExtras () .get ("key1") Toast.makeText (SecondActivity.this, "the first parameter obtained is:" + valueString+ "the second parameter is:" + valueString1,Toast.LENGTH_LONG) .show ();}}) Thank you for your reading, the above is "click the button in Android to start another Activity and how to solve the problem of passing values between Activity", after the study of this article, I believe you click on the button in Android to start another Activity and how to solve the problem of passing values between Activity have a more profound experience, the specific use of the situation also needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.