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.

  • what to return in onStartCommand for a service
  • Using facebook SDK on Android gives “User logged in as different Facebook user.” error
  • Getting error message “Resource is not public”
  • Android Layout - layoutweight and weightsum
  • Android set navigation drawer list to open exact half of the screen for all device screen
  • Is it possible to use Java 8 for Android development?
  • Related posts:

    How to blur background images in Android
    Can't scroll in a ListView in a swipeRefreshLayout
    Reading files from a ZIP file in your Android assets folder
    GCM : java.lang.noclassdeffounderror: com.google.android.gcm.GCMRegistrar
    Eclipse ADT Plugin - No Build Target Available
    Android Fragment and getWindow()
  • Images to Video using MediaCodec and MediaMuxer
  • How Picasso Actually Cache the Images
  • Can we post image on twitter using twitter API in Android?
  • Displaying UI widgets in Cardview in android L
  • get list of all users connected using wifi tethering in android
  • Does BroadcastReceiver.onReceive always run in the UI thread?
  • 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.