我怎样才能同时进行 2 个活动
我制作了一个可以计算输入字段中的数字的应用程序。 **主要活动 输入1 输入2 输入3 这些输入供用户输入数字。 input5 的预设数字为 9.5 input4 位于“详细信息”活动
“总计”中,应该添加 input1、input2、input3 和 input4
我遇到的问题是,当我尝试计算“总计”时,除非我转到该屏幕,否则不会从第二个活动中提取 input4 数字并返回主窗口,然后单击计算。任何人都可以帮助我弄清楚如何在主屏幕上的主活动的同时运行主要活动和详细活动。 感谢您的阅读并帮助我解决这个问题。
i have made an app that would calculate numbers from input fields.
**main Activity
input1
input2
input3
these input are for user to enter numbers.
input5 has a preset number of 9.5
input4 is in "details" activity
"Total" should add input1,input2,input3 and input4
the problem i am having is that when i try to calculate the "total" would not pull input4 number from the second Activity unless i go to that screen and go back to main then click on calculate. could anyone help me figure out how to run both main and the details activities at the same time with the main Activity on the main screen.
thank you for reading.and helping me through this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有多种方法可以跨活动共享静态数据。您可以使用
PreferenceManager
api、Service
甚至扩展Application
来保存全局数据。另一种方法是在创建新活动时将信息放入
Intent
中。使用putExtra("input1key",input1);
(假设您正在使用整数进行计算,您可以使用浮点数等),然后在您的新活动中。int input1 = getIntent().getIntExtra("input1key", 0);
There are a number of ways to share static data across activities. You could use the
PreferenceManager
api,Service
or even extendApplication
to hold your global data.Another way would be to put the info inside the
Intent
when you create your new activity. withputExtra("input1key",input1);
(assuming you are calculating with ints you could use float, etc) then in your new activity.int input1 = getIntent().getIntExtra("input1key", 0);
除了@schwiz 的回答之外,您还可以重新考虑您的设计。这里有必要使用2个activity吗?为什么?在这种情况下,使用 2 个活动有什么好处?不过,如果没有看到一些具体细节,我们确实无法回答。
Along with @schwiz's answer, you could also rethink your design. Is it necessary to use 2 activities here? Why? What benefit does using 2 activities provide in this case? We really can't answer without seeing some specifics though.