How to Pass Array to another activity?

I know that we can able to pass the any object with its value to another activity with the method putExtra() and getExtra methods.
but now I want to know whether is it possible to pass the array to the another Activity or not?
Or if it is then let me know how I can pass the array to the another Activity ?
Thanks.

  • Fragments, setRetainInstance(true), and threaded libraries
  • IllegalStateException at MediaCodec.dequeInputBuffer / dequeOutputBuffer
  • Android Exception: Did you forget to call 'public void setup (LocalActivityManager activityGroup)'
  • How to emulate GPS location in the Android Emulator?
  • How can I use Tensorflow with react-native?
  • System.currentTimeMillis() returns incorrect timestamp on Huawei
  • android linearlayout background selector
  • Need some clarification about beta/alpha testing on the developer console
  • Change tab background color and remove divider line between tabs
  • Write applications in C or C++ for Android?
  • SearchView in OptionsMenu not full width
  • START_STICKY does not work on Android KitKat
  • 5 Solutions collect form web for “How to Pass Array to another activity?”

    Bundle b=new Bundle();
    b.putStringArray(key, new String[]{value1, value2});
    Intent i=new Intent(context, Class);
    i.putExtras(b);
    

    And for receiveing

    Bundle b=this.getIntent().getExtras();
    String[] array=b.getStringArray(key);
    

    The Bundle class has many putXxxxArray() methods.

    1. putBooleanArray
    2. putByteArray
    3. putCharArray
    4. putCharSequenceArray
    5. putDoubleArray
    6. putFloatArray
    7. putIntArray
    8. putLongArray
    9. putParcelableArray
    10. putShortArray
    11. putStringArray

    If you are looking to pass some sort of Object, you should look at the Parcelable interface, as your Objects will need to implement it.

    Please see this question. Basically:

    Bundle b=new Bundle();
    b.putStringArray(key, new String[]{value1, value2});
    Intent i=new Intent(context, Class);
    i.putExtras(b);
    

    To retrieve:

    Bundle b=this.getIntent().getExtras();
    String[] array=b.getStringArray(key);
    

    Firstly, you should know two issues:

    • in order to send sth via an intent it must be parcelable
    • even if an object is pacelable, there is limitation to the amount of data you can send via an intent.

    A possible approach could be to have a static structure where you could store your data and pass with the intent only an index to that data. Using this index the new activity could get access to those data. Hope this helps.

     Intent intent = new Intent();
     Bundle bundle = new Bundle();
     bundle.putSerializable("bundle",Parceble Object);
     intent.putExtra(String key, String[] values);
     intent.putExtras(bundle);
    

    And for different types of array look here.

    Thnx

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.