Thanks for the kudos on Transfuse and the kind words.
It looks like the @OnActivityResult
event mapping was missing from Transfuse, but it was easy enough to add (https://github.com/johncarl81/transfuse/issues/47). You will have to use the current 0.2.3-snapshot to use this functionality, which should be available on maven central, until a non-SNAPSHOT is released.
Transfuse does not handle the Activity results via injected extras and for the time being it looks like you will need to handle this the regular Android way. The good news is Transfuse can help map in the button clicks and intent building. Here's an example:
Button listener to trigger intent in the first Activity:
@RegisterListener(R.id.resultonebutton)
public android.view.View.OnClickListener listener = new android.view.View.OnClickListener() {
@Override
public void onClick(android.view.View view) {
android.content.Intent intent = intentFactory.buildIntent(new ResultTwoActivityStrategy());
context.startActivityForResult(intent, REQUEST);
}
};
Button listener to return a result from the second Activity:
@RegisterListener(R.id.resulttwobutton)
public android.view.View.OnClickListener listener = new android.view.View.OnClickListener() {
@Override
public void onClick(android.view.View view) {
Intent returnIntent = new Intent();
returnIntent.putExtra(ResultOne.RESULT_KEY, inputText.getText().toString());
activity.setResult(android.app.Activity.RESULT_OK, returnIntent);
activity.finish();
}
};
Then the OnActivityResult method in the original Activity:
@OnActivityResult
public void result(int requestCode, int resultCode, android.content.Intent data) {
if (requestCode == REQUEST) {
if(resultCode == android.app.Activity.RESULT_OK){
String result=data.getStringExtra(RESULT_KEY);
Toast.makeText(context, result, SharedVariables.ONE_SECOND).show();
}
}
}
Don't forget that you can inject the current Activity, IntentFactory, and all Widgets.
To add flags to the intent, you simply need to build the intent and call the .addFlags() method. If you're using the IntentFactory it would look like this:
Intent intent = intentFactory.buildIntent(new ResultTwoActivityStrategy());
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
context.startActivity(intent, REQUEST);
It looks like the onNewIntent event is also missing. I will look at adding that soon along with any other recently added events.