我开始活动开始的意图取决于设备是组所有者还是仅仅是已加入的对等设备。目前,instructIntent未初始化。我是否应该按照Eclipse的建议让它变为空?或者是否有更专业的,Java代码风格的处理方式?如何在这种情况下初始化一个变量?
Intent instructIntent;
if (info.groupFormed && info.isGroupOwner) {
Log.d(WiFiDirectActivity.TAG, "DeviceDetailFragment_onCreateView: btn_ready pressed on host");
instructIntent = new Intent(getActivity(), LeaderActivity.class);
} else if (info.groupFormed) {
Log.d(WiFiDirectActivity.TAG, "DeviceDetailFragment_onCreateView: btn_ready pressed on client");
instructIntent = new Intent(getActivity(), MusicianActivity.class);
}
instructIntent.putExtra(Intent.EXTRA_TEXT, "Play");
instructIntent.putExtra(MusicService.EXTRAS_GROUP_OWNER_ADDRESS, info.groupOwnerAddress.getHostAddress());
instructIntent.putExtra(MusicService.EXTRAS_GROUP_OWNER_PORT, 8080);
startActivity(instructIntent);
And Intent instructIntent追到第一个if? – Chucky 2013-02-13 19:11:40
是的,因为它不会在那之外使用。尽管声明它更高级不会是一个错误,只是一种风格的东西。 – 2013-02-13 19:12:30
如果没有组成组件呢? – Chucky 2013-02-13 19:14:43