putStringArray() using String 2-Dimensional array (String[][] )

后端 未结 3 1186
失恋的感觉
失恋的感觉 2021-01-07 08:00

I want to pass a 2-D String Array to another activity. My S2-D String Array (String[][]) is \'selected_list\'.

code is :

     Bundle list_bundle=new         


        
3条回答
  •  走了就别回头了
    2021-01-07 08:33

    This finally works well for me : Thanks to Matthew and Mehdiway

    To start a new activity (sending String[][] and String):

    String[][] arrayToSend=new String[3][30];
    String stringToSend="Hello";
    Intent i = new Intent(this, NewActivity.class);
    
    i.putExtra("key_string",stringToSend);
    
    Bundle mBundle = new Bundle();
    mBundle.putSerializable("key_array_array",  arrayToSend);
    i.putExtras(mBundle);
    
    startActivity(i);
    

    To access in NewActivity.onCreate:

    String sReceived=getIntent().getExtras().getString("key_string");
    
    String[][] arrayReceived=null;
    Object[] objectArray = (Object[]) getIntent().getExtras().getSerializable("key_array_array");
    if(objectArray!=null){
        arrayReceived = new String[objectArray.length][];
        for(int i=0;i

提交回复
热议问题