Bundle bundleSend = new Bundle(); bundleSend.putBoolean(“JobRunning“, isCurr

Bundle bundleSend = new Bundle();
                        bundleSend.putBoolean("JobRunning", isCurrentJobRunning);
//                        bundleSend.putString("updateDistanceString", eyeXYZValText);
                        bundleSend.putString("updateString", updateString);  不传bundle了,传string类型

如果你想从传递一个 `Bundle` 对象改为直接传递一个 `String` 对象,你可以修改代码以适应这种变化。以下是修改后的代码示例:

### 原始代码(使用 Bundle):
```java
Bundle bundleSend = new Bundle();
bundleSend.putBoolean("JobRunning", isCurrentJobRunning);
//bundleSend.putString("updateDistanceString", eyeXYZValText);
bundleSend.putString("updateString", updateString);
```

### 修改后的代码(直接传递 String):
```java
String updateString = "Your update string here"; // 确保这里的值是你想要传递的字符串
// 直接传递 updateString 而不是通过 Bundle
```

### 如果你在一个方法中传递这个字符串,你可以这样调用:
```java
// 假设你有一个方法接受 String 参数
yourMethod(updateString);
```

### 如果你需要在 Intent 中传递这个字符串:
```java
Intent intent = new Intent(this, YourTargetActivity.class);
intent.putExtra("updateString", updateString);
startActivity(intent);
```

### 如果你需要在广播中包含这个字符串:
```java
Intent intent = new Intent("your.custom.action");
intent.putExtra("updateString", updateString);
sendBroadcast(intent);
```

### 如果你需要在回调或事件中传递这个字符串:
```java
// 定义一个回调接口或事件监听器,包含一个方法接受 String 参数
public interface YourCallback {
    void onStringReceived(String updateString);
}

// 实现这个接口
YourCallback callback = new YourCallback() {
    @Override
    public void onStringReceived(String updateString) {
        // 处理接收到的字符串
    }
};

// 触发回调或事件
callback.onStringReceived(updateString);
```

确保在代码的其他部分也相应地处理这种变化,即不要期望接收一个 `Bundle`,而是直接处理 `String` 对象。这样做可以简化代码,减少不必要的数据封装和解封装。
 

private Button login;// 登录按钮 private CheckBox rememberPsdBox, autoLoginBox;// 记住密码、自动登陆复选框 private EditText name, psd;// 用户名和密码 private TextView userInfo; SharedPreferences loginPreferences, accessPreferences;// 保存登陆信息和访问次数 SharedPreferences.Editor loginEditor, accessEditor;// 对应的编辑器 String userName; String userPsd; boolean isSavePsd,isAutoLogin; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); loginPreferences = this.getSharedPreferences("login", Context.MODE_PRIVATE); //补充完整-1:采用参数"access"和Context.MODE_PRIVATE,实例化accessPreferences对象 int count=accessPreferences.getInt("count",1); Toast.makeText(MainActivity.this,"欢迎您,这是第"+count+"次访问!", Toast.LENGTH_LONG).show(); loginEditor = loginPreferences.edit(); //补充完整-2:从accessPreferences中,实例化accessEditor编辑器 accessEditor.putInt("count",++count); accessEditor.commit(); //提交 userName = loginPreferences.getString("name", null); userPsd = loginPreferences.getString("psd", null); isSavePsd=loginPreferences.getBoolean("isSavePsd",false); isAutoLogin=loginPreferences.getBoolean("isAutoLogin", false); if (isAutoLogin) { this.setContentView(R.layout.activity_welcome); userInfo = (TextView) findViewById(R.id.userInfo); userInfo.setText("欢迎您:" + userName + ",登陆成功!"); } else{ loadActivity(); } } public void loadActivity() { this.setContentView(R.layout.activity_main); login = (Button) findViewById(R.id.login); rememberPsdBox = (CheckBox) findViewById(R.id.rememberPsd); autoLoginBox = (CheckBox) findViewById(R.id.autoLogin); name = (EditText) findViewById(R.id.name); psd = (EditText) findViewById(R.id.psd); if (isSavePsd) { psd.setText(userPsd); name.setText(userName); rememberPsdBox.setChecked(true); } login.setOnClickListener(new OnClickListener() { public void onClick(View v) { loginEditor.putString("name", name.getText().toString()); loginEditor.putString("psd", psd.getText().toString()); loginEditor.putBoolean("isSavePsd", rememberPsdBox.isChecked()); loginEditor.putBoolean("isAutoLogin", autoLoginBox.isChecked()); //补充完整-3:loginEditor的commit方法提交数据 MainActivity.this.setContentView(R.layout.activity_welcome); userInfo = (TextView) findViewById(R.id.userInfo); userInfo.setText("欢迎您:" + name.getText().toString() + ",登陆成功!"); } }); }补充代码
06-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值