How can i run 2 activities at the same time
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.
There are a number of ways to share static data across activities. You could use the PreferenceManager
api, Service
or even extend Application
to hold your global data.
Another way would be to put the info inside the Intent
when you create your new activity. with putExtra("input1key",input1);
(assuming you are calculating with ints you could use float, etc) then in your new activity. int input1 = getIntent().getIntExtra("input1key", 0);
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.
精彩评论