android intent 는 각종 구조 데 이 터 를 전달 합 니 다.

2295 단어 android
android intent 전달 list 또는 대상
방법 1: List이나 List만 전달 하면 바로 사용 할 수 있 습 니 다. 자바 코드 
intent.putStringArrayListExtra(name, value)  
intent.putIntegerArrayListExtra(name, value)  
방법 2: List를 전달 하면 list 를 Serializable 형식 으로 강하 게 바 꾸 고 통과 할 수 있 습 니 다. 자바 코드  putExtras(key, (Serializable)list)  방법 전달 자바 코드  (List) getIntent().getSerializable(key)  List데 이 터 를 받 아들 일 수 있 습 니 다. 하지만 Your Object 류 는 Serializable 인 터 페 이 스 를 실현 해 야 한 다 는 것 을 명심 하 세 요. 방법 3: 하 나 는... 자바 코드  Bundle.putSerializable(Key,Object);  다른 하 나 는... 자바 코드  Bundle.putParcelable(Key, Object);  물론 이 Object 들 은 일정한 조건 이 있 습 니 다.전 자 는 Serializable 인 터 페 이 스 를 실 현 했 고 후 자 는 Parcelable 인 터 페 이 스 를 실 현 했 습 니 다.
 
 
 
1.List과 List전달
다음은 List을 전달 하 는 예 로 List문법 을 보 냅 니 다.
intent.putStringArrayListExtra(key, list);
List을 받 는 문법 은:
list = (ArrayList)getIntent().getStringArrayListExtra(key);
다음은 인 스 턴 스 를 사용 하 는 것 입 니 다.
ArrayList stringList = new ArrayList(); stringList.add("string1"); stringList.add("string2"); stringList.add("string3"); Intent intent = new Intent(); intent.setClass(ListDemoActivity.this, StringListActivity.class); intent.putStringArrayListExtra("ListString", stringList); startActivity(intent); ArrayListstringList=(ArrayList)getIntent().getStringArrayList Extra("ListString")를 수신 합 니 다.
List와 유사 한 동작 으로 아래 의 방법 을 호출 하면 발송 과 수신 을 실현 할 수 있 습 니 다.intent.putInteger Array ListExtra(key,list);list =(ArrayList) getIntent().getIntegerArrayListExtra(key);
 
Intent 전달 문자열
intent.putExtra("key", "hello, world!");

 
수신 단 쓰기:
Intent intent = getIntent();
intent.getStingExtra("key"),  key             null;

 
 
 
 
 
 

좋은 웹페이지 즐겨찾기