![]() ![]() intent.putExtra("message", "This message comes from PassingDataSourceActivity's second button") Store the passed data in the above intent object by invoking its putExtra(String key, Object data) method, the key is a message key, the data is the passed data value.Intent intent = new Intent(PassingDataSourceActivity.this, PassingDataTargetActivity.class) ![]() Create a New Explicit or Implicit class’s instance in the Source Activity.String message = intent.getStringExtra("message") 3. The key should be the same as step 2 when invoking the intent object’s putExtra method. In the Target Activity, call the above intent object’s getStringExtra(String key) to get Source Activity passed data.In the Target Activity, call getIntent() method to get the Source Activity sent intent object.Invoke Source Activity object’s startActivity(intent) method to pass the intent object to the android os.intent.putExtra("message", "This message comes from PassingDataSourceActivity's first button") Invoke the above intent object’s putExtra(String key, Object data) method to store the data that will pass to Target Activity in it.Create an instance of class, pass the Source Activity object ( who sent the intent object ) and the Target Activity class ( who can receive the intent object ) to the Intent class constructor.Pass Data Between Activities Use Intent Object. If you click the second button in the Source Activity, it will pass data to the Target Activity also, and when you click the return button or click the android Back menu at the bottom in the Target Activity, the Source Activity can get the Target Activity returned response result data and display the result text in the Source Activity.If you click the first button in the Source Activity, it will pass data to the Target Activity, and when you click the return button in the Target Activity, the Source Activity can not get the response data from Target Activity.The Target Activity contains one button ( PASS RESULT DATA BACK TO SOURCE ACTIVITY ). ![]()
0 Comments
Leave a Reply. |