two things needed here:
first - Your custom view need to report it's score to the hosting Activity2
in order to achieve that make an interface called e.g.
public interface OnResult {
void onResult(int result);
}
make your Activity2 implement OnResult
, and let your custom DrawView class have a field OnResult resultCallback;
, and let the activity put itself as this field.
e.g.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
DrawView view = new DrawView (this); // "this" here as a Context object
view.setResultCallback(this); // "this" here as the OnResult listener object
setContentView(view);
}
and than, from your custom view when there is a result call your resultCallback.onResult() (that is, call the activity)
read more about callback mechanism via interfaces here
second - in your activity2 pass the answer back to activity 1
first of all, when starting activity2 from activity1 don't just start it using startActivity()
, but start it for a result using startActivityForResult()
and in your activity2 implementation of onResult()
from the first step, return the result via an intent and finish the activity -
Intent intent = new Intent();
intent.putExtra("editTextValue", "value_here")
setResult(RESULT_OK, intent);
finish();
read more about passing return values from one activity to another here (via @Uma Sankar)