我可以传递捆绑数据然后销毁 Activity 吗?
如果我尝试将数据从一个活动传递到另一个活动,但在进入另一个活动之前,我销毁了初始活动,那么我将无法传递数据。查看代码
//set bundle to pass data from initial activity
bundle = new Bundle();
data1 = Double.valueOf(myEditText.getText().toString());
bundle.putDouble("data1", data1);
Intent intent = new Intent(this, AnotherActivity.class);
intent.putExtras(bundle);
startActivity(intent);
finish();
当我现在尝试通过 AnotherActivity 获取数据时,
myBundle = getIntent().getExtras();
我什么也得不到。
If I try to pass data from one activity to another, but before going to another activity, I destroy the initial activity, then I cannot pass data. Look at the code
//set bundle to pass data from initial activity
bundle = new Bundle();
data1 = Double.valueOf(myEditText.getText().toString());
bundle.putDouble("data1", data1);
Intent intent = new Intent(this, AnotherActivity.class);
intent.putExtras(bundle);
startActivity(intent);
finish();
When I now try to get data in AnotherActivity via
myBundle = getIntent().getExtras();
I get nothing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我已经多次使用这种类型的代码,并且运行良好。
您需要检查 data1 = Double.valueOf(myEditText.getText().toString());
date1 是否为空?
需要在下一个活动中检查检索方法。
其他就没问题了。
I have used this type of code several time.and it's run fine.
You need to check out data1 = Double.valueOf(myEditText.getText().toString());
Is date1 is null?
Need to check retrieve method in next Activity.
other then no problem.
在这种情况下,bundle 和实例变量是吗?如果是这样,那可能就是问题所在。尝试为您要发送的特定意图创建一个新的捆绑包实例。
Is bundle in this case and instance variable? If so, that might be the problem. Try just creating a new bundle instance for this particular intent that you're going to send.
// 在另一个活动中
// in another activity