经过意图活动之间的数据 [英] pass data between activities with intent

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

问题描述

我的情况是特殊的一点点,所以我会在这里解释。 我有2个活动,先用2编辑和1键和第二只用一个按钮。 当pressing在活动1中的程序按钮发送意图的信息从文本编辑到活动2和活动2显示。 在活动2的按钮仅要回活动1,我这样称呼它

My case is a little bit of special so I will explain here. I have 2 activities, first with 2 edits and 1 button and second with just a button. When pressing the button in activity 1 the program sends with intent the informations from text edits to activity 2 and displays it on activity 2. On activity 2 the button is only to get back to activity 1 and i call it like this

    Button next = (Button) findViewById(R.id.button2);

    Intent myIntent = getIntent();
    String nume = myIntent.getStringExtra("nume");
    String prenume = myIntent.getStringExtra("prenume");
    next.setText(nume + " " + prenume);

    next.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            Intent intent = new Intent();
            setResult(RESULT_OK, intent);
            finish();
        }

    });

我第一次在编辑输入的相关信息,他们都显示正常的活动2,但在我回来的活性并进入新的价值观上的活动2编辑显示的值进入第一次。

The first time i enter infos in edits they are displayed ok in activity 2, but after I come back to activity 1 and enter new values on edits on the activity 2 are displayed the values entered first time.

所以,问题似乎是由意图通过编辑不会被我preSS按钮1传递到活动2开始的第二atempt每一次更新。

So the problem seems to be that the edits passed by intent wont be updated each time I press the button 1 to pass to Activity 2 starting with the second atempt.

推荐答案

导航从第一个到第二个:

Navigate from First to Second:

Button next = (Button) findViewById(R.id.button2);
next.setOnClickListener(new View.OnClickListener() {
    public void onClick(View view) {
        Intent intent = new Intent(getApplicationContext(),Second.class);
        intent.putExtra("Tag", "Value");
        startActivity(intent);
        finish();
    }

});

二,以第一:

Second to First:

 Button previous= (Button) findViewById(R.id.button);
 previous.setOnClickListener(new View.OnClickListener() {
    public void onClick(View view) {
        Intent intent = new Intent(getApplicationContext(),First.class);
        startActivity(intent);
    }

});

在创建第二个活动:

Intent i = getIntent();
String val = i.getStringExtra("Tag");

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

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