It is very common for native plugin to start some activities and wait for their result. Right now you need to subclass from UnityPlayerActivity and change activity class in AndroidManifest.xml. That’s completely ok for one plugin but start’s to be complicated when two plugins try to override acitivty class. So I suggest to amend UnityPlayerActivity class so we don’t need class override for such routine tasks.
private final CopyOnWriteArraySet<ActivityResultListener> mActivityResultListeners = new CopyOnWriteArraySet<>();
public void addActivityResultListener(ActivityResultListener listener) {
mActivityResultListeners.add(listener);
}
public void removeActivityResultListener(ActivityResultListener listener) {
mActivityResultListeners.remove(listener);
}
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) {
for (ActivityResultListener listener : mActivityResultListeners) {
listener.onActivityResult(requestCode, resultCode, data);
}
}
ActivityResultListener inteface is dead simple:
public interface ActivityResultListener {
/**
* Called when host (activity/service) receives an {@link Activity#onActivityResult} call.
*/
void onActivityResult(int requestCode, int resultCode, Intent data);
}