我正在尝试将一个字符串和一些整数传递给另一个活动。问题是整数可以成功传递,但字符串值不行。我在论坛中搜索了类似的问题,但我找不到我的问题。
主要活动类:
public void onClick(View v)
{
Intent debug = new Intent("bluetooth_4.pack.USBDebugMode");
if((port != null))
{
debug.putExtra("port", port.toString());
debug.putExtra("buadRate", buadRate);
debug.putExtra("dataBits", dataBits);
debug.putExtra("stopBits", stopBits);
debug.putExtra("parity", parity);
startActivity(debug);
Toast.makeText(MainActivity.this, "Switching to USB Debug Mode" , Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(MainActivity.this, "You haven't selected a device yet!" , Toast.LENGTH_SHORT).show();
}
}
新活动类:
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.usb_debug_main);
Button button1 = (Button) findViewById(R.id.button1);
Button button2 = (Button) findViewById(R.id.button2);
button1.setOnClickListener(myButtonListener1);
button2.setOnClickListener(myButtonListener2);
ActionBar actionBar = getActionBar();
actionBar.hide();
port = getIntent().getStringExtra(port);
buadRate = getIntent().getIntExtra("buadRate", 0);
dataBits = getIntent().getIntExtra("dataBits", 0);
stopBits = getIntent().getIntExtra("stopBits", 0);
parity = getIntent().getDoubleExtra("parity", 0);
mUsbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
TextView text = (TextView) findViewById(R.id.textView2);
text.append("Port: " + port + "\r\n");
text.append("Buad Rate: " + buadRate + "\r\n");
text.append("Data Bits: " + dataBits + "\r\n");
text.append("Stop Bits: " + stopBits + "\r\n");
text.append("Parity: " + parity + "\r\n");
}
我有一个文本框,它所做的只是显示一些数据,而诸如波特率、数据位、停止位和奇偶校验等参数有数据,端口总是返回空值。
但是,端口不能为空才能启动活动。