반응형

이번 포스팅은 ArrayList 객체를 Intent로 전달하는 방법에 대하여 알아보도록 하겠습니다.

 

1. 데이터 클래스의 직렬화

 

우선 인자로 전달하기 위해서는 ArrayList에 담기는 데이터 클래스가 직렬화(Serializable interface를 구현)가 되어 있어야 합니다.

 

public class Subway implements Serializable {

......

 

}

  

2. Intent에 데이터 담기

 

ArrayList <Subway> subwayList = new ArrayList <Subway>();

subwayList.add(new Subway(201, "시청"));

 

Intent intent = new Intent();

intent.putExtra("subway",  subwayList);

startActivity(intent);

 

3. 데이터 꺼내서 사용하기

 

ArrayList <Subway> subwayList = (ArrayList <Subway>) getIntent(). getSerializableExtra("subway");

반응형

'Development > Android' 카테고리의 다른 글

[Android] Activity 호출  (0) 2020.04.08
[Android ] Intent FLAG  (0) 2020.04.08
[Android] MoveEvent Value  (0) 2020.04.08
[Android] Picsasso vs Glide  (0) 2019.10.01
[Android] App Architecture 가이드 2  (0) 2019.09.23

+ Recent posts