Call user activity as startActivityForResult

I start the action for the result as

startActivityForResult(new Intent(this,ActivityA.class),REQUEST_CODE) 

ActivityA starts. There is a gridview for ActivityA, I want to get the position of the selected image in the onActivityResult (int requestCode, int resultCode, Intent data) method of the caller’s activity, but I don’t get a way to do this

+7
source share
1 answer

In action A,

onItemClick() of GridView

 //create a new intent... Intent intent = new Intent(); intent.putInt("position",position); setResult(RESULT_OK,intent); //close this Activity... finish(); 

in caller activity

  @Override protected void onActivityResult(int requestCode, int resultCode, Intent intent){ super.onActivityResult(requestCode, resultCode, intent); Bundle extras = intent.getExtras(); if(extras != null) int position = extras.getInt("position"); } 
+19
source

All Articles