Question

Intent intent = new Intent(Intent.ACTION_PICK, null);
intent.setType("image/*"); 
startActivityForResult(intent, TServiceInfo.ACTIVITY_PICSELECTED);

Like some code above, Activity will Jump into system gallery. But will startActivity run TServiceInfo.class or not?

TServiceInfo.ACTIVITY_PICSELECTED equals 4, can I write to this startActivityForResult(intent, 4); What's the difference between them?

(TServiceInfo.class is a connect-class between client and server)

Was it helpful?

Solution

There is no difference. Make sure you use the same as requestCode in onActivityResult().

OTHER TIPS

TServiceInfo.ACTIVITY_PICSELECTED is useful when you have multiple things to do in onActivityResult method !

Which also depends on many things like if u want that videos should be viewed in gallery / or for audio then you can set 2 more integer variables like ACTIVITY_VIDEO_SELECTED,ACTIVITY_AUDIO_SELECTED !

You can have many instances of

Intent intent = new Intent(Intent.ACTION_PICK, null);
intent.setType("video/*"); 
startActivityResult(intent, TServiceInfo.ACTIVITY_VIDEO_SELECTED);

Or

Intent intent = new Intent(Intent.ACTION_PICK, null);
intent.setType("audio/*"); 
startActivityResult(intent, TServiceInfo.ACTIVITY_AUDIO_SELECTED);

But You can have only one instance of onActivityResult ! So in this method you can use the values to predict that from which instance it has been called like :

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

      if (requestCode == TServiceInfo.ACTIVITY_PICSELECTED && resultCode == RESULT_OK &&null != data)
      {

                // do something here
      }
      if (requestCode == TServiceInfo.ACTIVITY_VIDEO_SELECTED && resultCode == RESULT_OK &&null != data)
      {
                 // do something here

      }
      if (requestCode == TServiceInfo.ACTIVITY_AUDIO_SELECTED && resultCode == RESULT_OK &&null != data)
      {
                 // do something here

      }
}

So by maintaining the values of these variables(ACTIVITY_PICSELECTED,ACTIVITY_VIDEO_SELECTED,ACTIVITY_AUDIO_SELECTED) You can predict which code should be executed !

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top