Skip to content Skip to sidebar Skip to footer

How To Use Onactivityresult Method From Other Than Activity Class

I am creating an app where i need to find current location of user . So here I would like to do a task like when user returns from that System intent, my

Solution 1:

When you start an activity with startActivityForResult method from an activity, only the caller will receive the result.

So you could handle the result and pass it to the task or update the UI of that activity:

int MY_REQUEST_ID = 1;

publicvoidonClick(){
    //Select a contact.
    startActivityForResult(
             new Intent(Intent.ACTION_PICK,
             new Uri("content://contacts")),
             MY_REQUEST_ID);
}    

protectedvoidonActivityResult(int requestCode, int resultCode, Intent data) {
     if(requestCose == MY_REQUEST_ID && resultCode == SUCCESS) {
         MyAsyncTask task = new AsyncTask(requestCode, resultCode, data);
         task.execute();
         // or update the UI
         textView.setText("Hi, activity result: "+ resultCode);
     }
}

Post a Comment for "How To Use Onactivityresult Method From Other Than Activity Class"