Difference between StartActivityForResult, startActivity

Many of them  have confution about startActivity and startActivityForResult() methods.
startActivity() is to start another activity
StartActivityForResult() is to receive a result. The activity has to return a result.
When it returns a result, it sends as another intent object and activity recives result in onActivityResult() and here we can handle.
We need to pass an integer arg to startActivityForResult() method. So that request code will identifies the request.
When you get the result intent, callback provides the same request code to identify the result.

see this example:
  Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(intent, 1);
@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == 1){           
        }       


Comments

Popular posts from this blog

What is Android ?