Android的传球意图previous活动 [英] Android pass intent to previous Activity

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

问题描述

我要一些数据发送到previous活动。但是,这是行不通的。

I want to send some data to previous Activity. But it does not work.

在这里,我需要发送一些数据。

here i need to send some data .

 btnSaveRecord = (Button)findViewById(R.id.buttonSaveRecord);
        btnSaveRecord.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {

                Intent intent = new Intent(Record_Audio.this , AddPost.class);
                intent.putExtra("STRING_I_NEED", newAudioFile);

                startActivity(intent);
                finish();

            }
        });

下面是我的previous活动

Here is my previous Activity

 if (savedInstanceState == null)
        {
            Bundle extras = getIntent().getExtras();
            if(extras == null)
            {
                newString= null;
                Log.e("111"," = "+newString);
            }
            else
            {
                newString= extras.getString("STRING_I_NEED");
                Log.e("222"," = "+newString);
            }
        } else
        {
            newString= (String) savedInstanceState.getSerializable("STRING_I_NEED");
            Log.e("333"," = "+newString);
        }

什么code做我需要在这里,我不明白为什么不能正常工作。

What code do i need here , I don't understand why not work.

推荐答案

尝试越来越结果从活动

要总结文章:

static final int REQUEST_CODE = 1;  // The request code
...
private void itemClicked() {
    Intent intent = new Intent(this, SecondActivity.class);
    // Add any data that you wish to send
    intent.putExtra("DATA", "value");
    startActivityForResult(pickContactIntent, REQUEST_CODE);
}

在你的第二个活动,接收到的数据要修改:

In your second activity, receive the data you wish to modify:

字符串valueToChange = getIntent()getExtras()的getString(DATA);

String valueToChange = getIntent().getExtras().getString("DATA");

然后把它放在任何你想用它做一个编辑文字或者,当你完成其设置为结果包。

Then put it in an Edit text or whatever you want to do with it, when you are done set it as the result bundle.

// Create the result Intent
Intent intent = new Intent();
intent.putExtra("RESULT", "YourNewString");
setResult(Activity.RESULT_OK, intent);
finish();

在您的第一项活动,覆盖的onActivityResult 来获得的价值。

In your first activity, override onActivityResult to get the value.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // Check which request it is that we're responding to
    if (requestCode == REQUEST_CODE) {
        if (resultCode == RESULT_OK) {
             String newString = data.getExtras().getString("RESULT");
         }
    }
}

您可能还需要通过数组中的项目位置发送,这样就可以对其进行更新。

You may also want to send through the items position in the array so that you can update it.

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

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