왕현성
코딩발자취
왕현성
전체 방문자
오늘
어제
  • 코딩 (277)
    • Python (71)
    • Java (16)
    • MySQL (34)
    • 인공지능 (48)
      • 머신러닝 (16)
      • 딥러닝 (32)
    • 영상처리 (4)
    • Rest API (21)
    • Android Studio (25)
    • streamlit (13)
    • DevOps (22)
      • AWS (9)
      • PuTTY (5)
      • Git (4)
      • Serverless (2)
      • Docker (2)
    • IT 기술 용어 (6)
    • 디버깅 ( 오류 해결 과정 ) (17)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • encoding='utf-8'
  • 영상처리역사
  • alibi-detection
  • alibidetect
  • 영상처리
  • yolov8
  • 의료이미징
  • get_long_description
  • pip install labelme
  • unsupervised
  • labelme UnocodeDecodeError
  • ComputerVision
  • numpy
  • OpenCV
  • PYTHON
  • 기상탐사
  • PIL
  • UnboundLocalError
  • tune()
  • matplotlib
  • 딥러닝
  • 비지도학습
  • ckpt_file
  • 컴퓨터비전
  • maskimage
  • imageprocessing
  • labelme
  • 영상기술
  • TensorFlow
  • pytorch

최근 댓글

최근 글

티스토리

250x250
hELLO · Designed By 정상우.
왕현성

코딩발자취

Android Studio

Android - 다른 Activity로 데이터 전달 시 클래스의 객체를 전달하는 방법 Serializable , putExtra(), getSerializableExtra()

2023. 2. 1. 17:49
728x90

1. Serializable (직렬화)

클래스 정의시 뒤에 implements Serializable 정의

내부에서 사용되는 객체 데이터를 외부에서도 사용 할 수 있도록 해주는 것

 

객체 자체에 여러가지 정보를 담아 다른 액티비티에게 데이터를 전달하는 방법

  • 여러가지의 데이터를 보낼 경우 하나하나 일일이 지정하지 않고 객체 자체에 정보를 담는 것이 유용
  • 예를 들면 회원가입시 회원의 정보를 일일이 지정하지 않고 객체에 담아 전달하는 것이 편리

 

public class Contact implements Serializable {

    public int id;
    public String name;
    public String phone;

 

2. putExtra()

지금까지는 주석처리한 코드와 같이 3줄을 작성해야했지만, 직렬화 이후엔 1줄로 작성 가능

//                    intent.putExtra("id",contact.id);
//                    intent.putExtra("name",contact.name);
//                    intent.putExtra("phone",contact.phone);
                    intent.putExtra("contact",contact);

 

3. getSerializableExtra()

주석처리한 5줄을 3줄로 줄여 작성 가능.

//        int id = getIntent().getIntExtra("id",0);
//        String name = getIntent().getStringExtra("name");
//        String phone = getIntent().getStringExtra("phone");
//        editName.setText(name);
//        editPhone.setText(phone);
        Contact contact = (Contact) getIntent().getSerializableExtra("contact");
        editName.setText(contact.name);
        editPhone.setText(contact.phone);

'Android Studio' 카테고리의 다른 글

Android - 실시간 검색기능 개발 ( TextWathcer )  (0) 2023.02.03
Android - 화면 갱신 함수 notifyDataSetChanged()  (0) 2023.02.02
Android - RecyclerView 어댑터에서 새로운 액티비티 실행하는 방법과 몇 번째 행을 눌렀는지 알 수 있는 getAdapterPosition()  (0) 2023.02.01
Android - RecyclerView - 리스트를 화면에 출력하기  (0) 2023.02.01
Android - SQLite3 DB 사용법  (1) 2023.01.31
    'Android Studio' 카테고리의 다른 글
    • Android - 실시간 검색기능 개발 ( TextWathcer )
    • Android - 화면 갱신 함수 notifyDataSetChanged()
    • Android - RecyclerView 어댑터에서 새로운 액티비티 실행하는 방법과 몇 번째 행을 눌렀는지 알 수 있는 getAdapterPosition()
    • Android - RecyclerView - 리스트를 화면에 출력하기
    왕현성
    왕현성
    AI 머신비전 학습일지

    티스토리툴바