![]() ![]() The first parameter can be _OK or RESULT_CANCELED, the second parameter is the intent object. Call setResult(RESULT_OK, intent) method in the Target Activity to set the returned intent in android os.intent.putExtra("message_return", "This data is returned when user click button in target activity.") Call above intent object’s putExtra(String key, Object data) method to set the returned result data in the intent object.Do not need to provide constructor parameters at this time. To return data back to Source Activity from the Target Activity, you should create an instance of class in the Target Activity.startActivityForResult(intent, REQUEST_CODE_1) The first parameter is the intent object, the second parameter is a user-defined integer number that is used to check whether the returned intent object is related to this request. If you want to get the response data from the Target Activity, now you should call startActivityForResult(Intent intent, int requestCode) method in the Source Activity, this method will pass the intent object to android os and wait for the response from the Target Activity. ![]() 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") ![]()
0 Comments
Leave a Reply. |