Android的活动之间传递数据 [英] Passing data between activities android

查看:221
本文介绍了Android的活动之间传递数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  <一href=\"http://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-in-android\">How我传递活动之间的数据,Android的?

我一直在敲我的桌子对面的头几天试图弄清楚这一点。我是新来的Java和Android平台,我写我的第二个应用程序。概括地说,我希望用户在第一个活动的一些信息输入。然后该活动发生的那些输入和运行一系列数学计算的,然后在一个单独的活动显示在几个editTexts结果。在我的印象中,应用程序需要的投入,运行计算,然后将它们存储在一些变量。变量然后需要被传递到第二活动的屏幕上显示结果。我有大部分的应用程序$ C $的CD,我可以得到它正常工作,如果我把输入和显示的结果中的一项活动。我如何能得到所显示的结果显示在另一个活动的任何想法?这里的任何方向是非常AP preciated。

I have been banging my head across the table for days trying to figure this out. I'm new to both Java and the Android platform and I am writing my second application. In a nutshell, I want the user to enter in some information in the first activity. That activity then takes those inputs and runs a series of mathematical computations and then displays the results in several editTexts in a separate activity. In my mind, the application takes the input, runs the computations and then stores them in some variables. The variables then need to be passed to the second activity which then displays the results. I have most of the application coded and I can get it to work properly if I keep the inputs and displayed results in one activity. Any Ideas on how I can get the displayed results to show up on another activity? Any direction here is much appreciated.

推荐答案

这可以和使用意图的实现。使用意向中的一个是通过活动之​​间的数据。在你的情况下,您需要做的就是

This can be done with use of intent. one of the use of Intent is to pass the data between activities. In your scenario what you need to do is

以用户输入后,执行运算,结果存储到
   变量结果
捆绑在你正在使用的意图
    开始下一个活动。您可以通过以下code ++实现这个

After taking input from the user, do computation, store result in the variables
bundle that in the intent which you are using to start next activity. You can achieve this by below code

Intent intent = new Intent();
            intent.putExtra("KeyForResult1", <your variable>);
            intent.putExtra("KeyForResult2",<your variable>);
            startActivity(this, nextactivity.class);

在nextactivity你需要得到的意图,并在变量提取值
   这可以实现

in the nextactivity you need to get the intent and extract the values in the variable which can be achieved

variabletype variable = getIntent().getExtras().get("KeyForResult1");
   variabletype variable = getIntent().getExtras().get("KeyForResult2");

这篇关于Android的活动之间传递数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆