Search code examples
androidandroid-activityserializable

Unable to pass an object of a class from one activity to another?


Code for passing the Object in the passing class

final ArrayList<SongDetails> Songinfo = getSongsFromDirectory(f);
public void onItemClick(AdapterView a, View v, int position, long id) {


               Intent intent = new Intent(getActivity(), NowPlaying.class);
               intent.putExtra("Data1",songinfo);

               intent.putExtra("Data2",position);
               startActivity(intent);

                     }
             });

code in the retrieving class

Intent i = getIntent();


        ArrayList<SongDetails> Songinfo2 = (ArrayList<SongDetails>)i.getSerializableExtra("Data1"); 
        position=i.getIntExtra("Data2", 1);

i have implemented Serializable in both the classes as well as in the class SongDetails class(of which i am passing the object of)


Solution

  • Consider using parcels.....

    using parcels is a better and faster way then using serializable