Getting a Result from an Activity




Beginning another movement doesn’t need to be one-way. You can likewise begin another action and get an outcome back. To get an outcome, call startActivityForResult() (instead than startActivity()).

For instance, your application can begin a camera application and get the caught photograph subsequently. On the other hand, you may begin the People application all together for the client to choose a contact and you’ll get the contact subtle elements subsequently.

Obviously, the action that reacts must be intended to give back an outcome. When it does, it sends the outcome as another Intent article. Your movement gets it in the onActivityResult() callback.

Example –

static final int PICK_CONTACT_REQUEST = 1;   
...
private void pickContact() {
    Intent pickContactIntent = new Intent(Intent.ACTION_PICK, Uri.parse("content://contacts"));
    pickContactIntent.setType(Phone.CONTENT_TYPE);    
    startActivityForResult(pickContactIntent, PICK_CONTACT_REQUEST);
}

Receive the Result

At the point when the client is finished with the ensuing movement and returns, the framework calls your action’s onActivityResult() strategy. This strategy incorporates three contentions:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
     if (requestCode == PICK_CONTACT_REQUEST) {
         if (resultCode == RESULT_OK) {
-------------
-------------

         }
    }
}

 


Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com





Be the first to comment

Leave a Reply

Your email address will not be published.


*