Java 保存来自两个站点的信息使用SharedReferences从按钮单击编辑文本

Java 保存来自两个站点的信息使用SharedReferences从按钮单击编辑文本,java,android,Java,Android,我正在尝试使用SharedReferences从一个活动的2个edittext获取另一个活动的2个文本视图。 虽然我已经成功地使用了这个方法,但它只是一个edittext对一个textview。   这次我不知道出了什么问题,因为我无法访问我定义的字符串,只能获取我输入的默认值。   希望你们能帮助我   提前谢谢 第一项活动: eActname = (EditText) findViewById(R.id.eACTName);                 eActbud = (EditTe

我正在尝试使用SharedReferences从一个活动的2个edittext获取另一个活动的2个文本视图。 虽然我已经成功地使用了这个方法,但它只是一个edittext对一个textview。   这次我不知道出了什么问题,因为我无法访问我定义的字符串,只能获取我输入的默认值。   希望你们能帮助我   提前谢谢

第一项活动:

eActname = (EditText) findViewById(R.id.eACTName);
                eActbud = (EditText) findViewById(R.id.eACTBud);
                nameData = getSharedPreferences(namefilename, 0);
                budData = getSharedPreferences(budfilename, 0);
 
                bCreate = (Button) findViewById(R.id.bCreateActivity);
                bCreate.setOnClickListener(new View.OnClickListener() {
 
                        @Override
                        public void onClick(View v) {
                                // TODO Auto-generated method stub
                                Intent o = new Intent(ActivityCreate.this, ActView.class);
                                String[] actstrings = new String[] {
                                                eActname.getText().toString(),
                                                eActbud.getText().toString() };
                                o.putExtra("string", actstrings);
 
                                switch (v.getId()) {
                                case R.id.bCreateActivity:
                                        bCreateClick();
 
                                        break;
                                }
                        }
 
                        private void bCreateClick() {
                                // TODO Auto-generated method stub
                                String namestringData = eActname.getText().toString();
                                SharedPreferences.Editor editor = nameData.edit();
                                editor.putString("namesharedString", namestringData);
                                editor.commit();
                                String budstringData = eActbud.getText().toString();
                                SharedPreferences.Editor budeditor = budData.edit();
                                budeditor.putString("budsharedString", budstringData);
                                budeditor.commit();
tvActName = (TextView) findViewById(R.id.tvActName);
                tvActBud = (TextView) findViewById(R.id.tvActBud);
                Intent o = getIntent();
                o.getStringArrayExtra("strings");
                tvActName.setText(o.getStringExtra("text"));
                tvActBud.setText(o.getStringExtra("text"));
                nameData = getSharedPreferences(namefilename, 0);
                budData = getSharedPreferences(budfilename, 0);
                String [] actdataReturned = {nameData.getString("namesharedString", "Error"), budData.getString("budsharedString", "Error")} ;
                
                tvActName.setText(actdataReturned[0]);
                tvActBud.setText(actdataReturned[1]);
现在是第二个活动的代码:

eActname = (EditText) findViewById(R.id.eACTName);
                eActbud = (EditText) findViewById(R.id.eACTBud);
                nameData = getSharedPreferences(namefilename, 0);
                budData = getSharedPreferences(budfilename, 0);
 
                bCreate = (Button) findViewById(R.id.bCreateActivity);
                bCreate.setOnClickListener(new View.OnClickListener() {
 
                        @Override
                        public void onClick(View v) {
                                // TODO Auto-generated method stub
                                Intent o = new Intent(ActivityCreate.this, ActView.class);
                                String[] actstrings = new String[] {
                                                eActname.getText().toString(),
                                                eActbud.getText().toString() };
                                o.putExtra("string", actstrings);
 
                                switch (v.getId()) {
                                case R.id.bCreateActivity:
                                        bCreateClick();
 
                                        break;
                                }
                        }
 
                        private void bCreateClick() {
                                // TODO Auto-generated method stub
                                String namestringData = eActname.getText().toString();
                                SharedPreferences.Editor editor = nameData.edit();
                                editor.putString("namesharedString", namestringData);
                                editor.commit();
                                String budstringData = eActbud.getText().toString();
                                SharedPreferences.Editor budeditor = budData.edit();
                                budeditor.putString("budsharedString", budstringData);
                                budeditor.commit();
tvActName = (TextView) findViewById(R.id.tvActName);
                tvActBud = (TextView) findViewById(R.id.tvActBud);
                Intent o = getIntent();
                o.getStringArrayExtra("strings");
                tvActName.setText(o.getStringExtra("text"));
                tvActBud.setText(o.getStringExtra("text"));
                nameData = getSharedPreferences(namefilename, 0);
                budData = getSharedPreferences(budfilename, 0);
                String [] actdataReturned = {nameData.getString("namesharedString", "Error"), budData.getString("budsharedString", "Error")} ;
                
                tvActName.setText(actdataReturned[0]);
                tvActBud.setText(actdataReturned[1]);

当您将数据写入您将其命名为“字符串”的意图时,当您读取将其命名为“字符串”的数据时。

这并不能解决问题,我一直获得默认值,因为我认为出于某种原因,它无法访问字符串