// First activity Intent intent = new Intent(this, SecondActivity.class); intent.putExtra("name", "John"); startActivity(intent); // Second activity Intent intent = getIntent(); Bundle extras = intent.getExtras(); if (extras != null) { String name = extras.getString("name"); }
// First activity final int REQUEST_CODE = 1; Intent intent = new Intent(this, SecondActivity.class); startActivityForResult(intent, REQUEST_CODE); @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) { // Handle result from second activity } } // Second activity Intent intent = new Intent(); intent.putExtra("result", "success"); setResult(RESULT_OK, intent); finish();Package library: android.app