简体   繁体   English

如何在android中将多个字符串从一个活动转移到另一个活动

[英]how to transfer more then one string from one activity to another in android

i have to transfer more then one string from one activity to another activity in android , i already know how to transfer one string from one to another string in android but for more then one string i can not found ways my code is here , 我必须在android中将一个字符串从一个活动转移到另一个活动,我已经知道如何在android中将一个字符串从一个字符串转移到另一个字符串但是对于多个字符串我找不到我的代码在这里的方式,

 if (long_insert_row_index>0){
                        //Spinner spDepCMPName = (Spinner) findViewById(R.id.spDepCMPName);
                        // String strCMP= spDepCMPName.getSelectedItem().toString();
                        //String strCMP=depositecmpname;

           //startActivity(new Intent(DepositActivity.this, AuditPointDetailsActivity.class).putExtra("insert_row_index",""+long_insert_row_index).putExtra("segment_name", spinner_segment.getSelectedItem().toString()).putExtra("audit_type_name", spinner_audit_type.getSelectedItem().toString()).putExtra("audit_type_id", audit_type_id).putExtra("segment_id", segment_id));


///please see commented section at bottom
                      startActivity(new Intent(DepositActivity.this, DepositeNextActivity.class)
                                .putExtra("insert_row_index",""+long_insert_row_index)
                                .putExtra("CMPName", depositecmpname));
                    }else {
                        Toast.makeText(DepositActivity.this,"Error while inserting data.Please re-enter data.",Toast.LENGTH_LONG).show();
                    }
                }

Now i want to send both string from one activity to another , i dont know how to do that one . 现在我想将一个字符串从一个活动发送到另一个活动,我不知道该怎么做。

you can use code in your first activity like :- 你可以在第一个活动中使用代码,如: -

  ArrayList<String> arr = new ArrayList<String>();
    arr.add(long_insert_row_index);
    arr.add( depositecmpname);
    Intent intent = new Intent(firstactivity.this,secondActivity.class);
                intent.putExtra("array_list", arr);
                startActivity(intent);

Now in another class you can use this code saying :- 现在在另一个类中,您可以使用此代码说: -

Bundle extras = getIntent().getExtras();

ArrayList<String> arr = (ArrayList<String>)extras.getStringArrayList("array_list");
          Toast.makeText(getApplicationContext(),""+arr.size(),Toast.LENGTH_LONG).show();

hope it will help 希望它会有所帮助

Use for open activity: 用于开放活动:

Intent intent = new Intent(activity, Activity2.class);
            intent.putExtra("String1", "Hello!");
            intent.putExtra("String2", "Hello!2")
            activity.startActivity(intent);

In open activity: 在公开活动中:

getIntent.getStringExtra("String1");
getIntent.getStringExtra("String2");

Or use 或者使用

intent.putExtra("StringByteArr", "str".toByteArray());

and: 和:

String.valueOf(getIntent.getByteArrayExtra("StringByteArr"));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在android中将数据从一个活动传输到另一个活动 - How to transfer data from one activity to another in android 如何在Android中将数据从一项活动转移到另一项活动? - How do I transfer data from one activity to another in Android? 如何将数据从一个活动转移到另一个活动? - How to transfer data from one activity to another? 从一项活动转移到另一项活动 - Transfer from one activity to another 如何在Android Studio中将控制权从一个活动转移到另一个活动的片段? - How to transfer control from one activity to fragment of another activity in android studio? Android - 如何将ImageView从一个活动转移到另一个活动? - Android - how can i transfer ImageView from one activity to another activity? 如何保存并将超过5个Edit Text的值从一个活动转移到另一个活动? - How to save and transfer the value of more than 5 edit Text from one activity to another? 在android中分配对象以从一个活动转移到另一个活动 - Parceling objects in android to transfer from one activity to another 如何在 Android 中从一个片段转移到另一个片段 - How to transfer from one fragment to another in Android 如何通过同一活动将从一个片段的列表视图选择的字符串传输到另一个片段的autocompleteTextview - How to transfer string selected from listview of one fragment to autocompleteTextview of another fragment over the same activity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM