startActivityForResult() sample code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Activity2 extends AppCompatActivity { | |
public static final String RESULT = "result"; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_2); | |
Bundle bundle = getIntent().getExtras(); | |
if (bundle != null) { | |
String messageFromActivity = bundle.getString(MESSAGE); | |
if (messageFromActivity != null && messageFromActivity.length() >= 3) { | |
String response = "Yes, I'm here"; | |
Intent intent = new Intent(); | |
intent.putExtra(RESULT, response); | |
setResult(RESULT_OK, intent); | |
finish(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment