我正在尝试将片段中的字符串发送到服务,如下面的代码:
public static class PlaceholderFragment extends Fragment implements OnClickListener{
public final static String EXTRA_STATUS = "";
public final static String EXTRA_ADDRESS = "";
public final static String EXTRA_NAME = "";
Intent Intent = new Intent(getActivity() , Alarm.class);
Intent.putExtra(EXTRA_STATUS, "1");
Intent.putExtra(EXTRA_ADDRESS, "2");
Intent.putExtra(EXTRA_NAME, "3");
getActivity().startService(Intent);
但在StartCommand
的{{1}}。它只获取我设置为Service
的最后一个字符串。
intent
在服务中,日志显示:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i("AlarmDialog", "AlarmDialog!!! address = " + intent.getStringExtra(PlaceholderFragment.EXTRA_ADDRESS));
Log.i("AlarmDialog", "AlarmDialog!!! name = " + intent.getStringExtra(PlaceholderFragment.EXTRA_NAME));
Log.i("AlarmDialog", "AlarmDialog!!! status = " +intent.getStringExtra(PlaceholderFragment.EXTRA_STATUS)) ;
return super.onStartCommand(intent, flags, startId);
}
我错过了什么?
提前致谢。
答案 0 :(得分:2)
public final static String EXTRA_STATUS = "";
public final static String EXTRA_ADDRESS = "";
public final static String EXTRA_NAME = "";
更改为
public final static String EXTRA_STATUS = "status";
public final static String EXTRA_ADDRESS = "address";
public final static String EXTRA_NAME = "name";
因为它的空字符串最后一个值为3会被标记。在所有情况下都可以看到相同的