4

I have a collection of data in ArrayList holding serializable model with following data types :-

  1. boolean isChecked
  2. String name
  3. String detail

I want to pass these datas from First Activity to Second Activity and edit the boolean state of isChecked using listView adapter with adapter callback .when I come back to First Activity I want to update the data from Second Activity.

I am able to pass data and Update it in second Activity but not able to get updated data in First Activity. How is it possible to achieve my requirement,Any kind of help is much appreciated Thank you

Seek Addo
  • 1,871
  • 2
  • 18
  • 30

3 Answers3

4

You can pass like this below

First Method

1) Implements your object class to serializable

public class Question implements Serializable

2) Put this in your Source Activity

ArrayList<Question> mQuestionList = new ArrayList<Question>;
mQuestionsList = QuestionBank.getQuestions();
mQuestionList.add(new Question(ops1, choices1));

Intent intent = new Intent(SourceActivity.this, TargetActivity.class);
intent.putExtra("QuestionListExtra", mQuestionList);

3) Put this in your Target Activity

ArrayList<Question> questions = new ArrayList<Question>();
questions = getIntent().getSerializableExtra("QuestionListExtra");

Second Method

Notice You model class must implements Parcelable

List<Bird> birds = new ArrayList<Bird>();
//birds.add();
Intent intent = new Intent(Current.this, Transfer.class);
Bundle bundle = new Bundle();
bundle.putParcelableArrayList("Birds", birds);
intent.putExtras(bundle);
startActivity(intent);

Recive like this

List<Bird> challenge = this.getIntent().getExtras().getParcelableArrayList("Birds");
Mick
  • 30,759
  • 16
  • 111
  • 130
Sohail Zahid
  • 8,099
  • 2
  • 25
  • 41
0

You have to use startActivityForResult here. Need to pass your model arraylist again back to the activity one.

Refer the below code to achieve what you want.

How to pass data from 2nd activity to 1st activity when pressed back? - android

Community
  • 1
  • 1
Arpit Ratan
  • 2,976
  • 1
  • 12
  • 20
0

Consider serializing this as string, put it as extra in an intent and deserialize it in the 2nd activity.

ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97