I have in an activity an ArrayList<ArrayList<String>>
, so basically a list of lists.
What I would like to accomplish, is to send from Activity 1 to Activity 2 this List of Lists, so I thought about intents, but I don't seem to be able to find the necessary getExtra().
To be more precise, questions
contains Strings
related to a question, and the corresponding position in answers
contains all the selected answers to that question.
public class ReviewActivity extends AppCompatActivity {
ArrayList<String> questions = new ArrayList<>();
ArrayList<ArrayList<String>> answers = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_review);
Intent intent = getIntent();
questions = intent.getStringArrayListExtra("questions");
answers = intent.getStringArrayListExtra("answers");
}
This is how I put the original ArrayList<ArrayList<String>>
in the intent:
Intent mIntent = new Intent(this, ReviewActivity.class);
mIntent.putExtra("questions", questions);
mIntent.putExtra("answers", answers);
startActivity(mIntent);
The code gives an error at the line answers = intent.getStringArrayListExtra("answers");
and I understand why, but how can I make a workaround?
Thanks.