在我的 Android 应用程序中有一个视图,“管理播放器”,其中有一个“添加播放器”视图。在“添加播放器”视图中,我正在访问相机,因此我对 onActivityResult 进行了覆盖。当它点击这个时,在“管理玩家”活动中,“添加玩家”视图现在为空。这是代码示例:
public class ManagePlayersActivity {
private AddPlayerView addPlayerView = null;
private ManagePlayersView view;
private Context context;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
context = this;
view = ManagePlayersViewFactory.create(this);
setContentView(view.asView());
public void onEvent(ClickEvent event) {
final Dialog d = new Dialog(context);
ManagePlayersActivity.this.addPlayerView = AddPlayerViewFactory.create(context);
ManagePlayersActivity.this.addPlayerView.setButtonPhotoPickerOnClickListener(new EventListener<ClickEvent>() {
public void onEvent(ClickEvent event) {
ManagePlayersActivity.this.addPlayerView.setPlayerPhoto("Setting Photo");
PackageManager pm = context.getPackageManager();
if (pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
}
});
d.show();
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUEST) {
if (resultCode == RESULT_OK) {
ManagePlayersActivity.this.addPlayerView.setPlayerPhoto("Photo set");
}
}
}
}
因此,在这样做之后,onActivity 结果中的 addPlayerView 为空。老实说,我对 Android 和 Java 还很陌生,我是一个没有 MVC 经验的 ac# Web 开发人员,所以这可能是对它的基本工作原理的误解。但是,任何帮助将不胜感激!
谢谢,安迪