startActivity ()에서 번들을 전달 하시겠습니까?
현재 번들에서 시작된 활동에 번들을 전달하는 올바른 방법은 무엇입니까? 공유 속성?
몇 가지 옵션이 있습니다.
Intent mIntent = new Intent(this, Example.class);
Bundle extras = mIntent.getExtras();
extras.putString(key, value);
2) 새 번들 생성
Intent mIntent = new Intent(this, Example.class);
Bundle mBundle = new Bundle();
mBundle.putString(key, value);
mIntent.putExtras(mBundle);
3) 의도 의 putExtra () 단축키 메소드를 사용하십시오.
Intent mIntent = new Intent(this, Example.class);
mIntent.putExtra(key, value);
그런 다음 시작된 활동에서 다음을 통해 읽을 수 있습니다.
String value = getIntent().getExtras().getString(key)
참고 : 번들에는 모든 기본 유형, Parcelable 및 Serializable에 대해 "get"및 "put"메소드가 있습니다. 방금 데모 목적으로 문자열을 사용했습니다.
인 텐트에서 번들을 사용할 수 있습니다.
Bundle extras = myIntent.getExtras();
extras.put*(info);
또는 전체 번들 :
myIntent.putExtras(myBundle);
찾고 계십니까?
안드로이드에서 하나의 활동에서 활동으로 데이터 전달
의도에는 작업 및 선택적으로 추가 데이터가 포함됩니다. 인 텐트 putExtra()
방법을 사용하여 데이터를 다른 활동으로 전달할 수 있습니다 . 데이터는 엑스트라로 전달되며 key/value pairs
입니다. 키는 항상 문자열입니다. 값으로 기본 데이터 유형 int, float, chars 등을 사용할 수 있습니다. 또한 Parceable and Serializable
한 활동에서 다른 활동으로 오브젝트를 전달할 수도 있습니다 .
Intent intent = new Intent(context, YourActivity.class);
intent.putExtra(KEY, <your value here>);
startActivity(intent);
안드로이드 활동에서 번들 데이터 검색
getData()
Intent 오브젝트의 메소드를 사용하여 정보를 검색 할 수 있습니다 . 인 텐트 오브젝트는 getIntent()
메소드 를 통해 검색 할 수 있습니다 .
Intent intent = getIntent();
if (null != intent) { //Null Checking
String StrData= intent.getStringExtra(KEY);
int NoOfData = intent.getIntExtra(KEY, defaultValue);
boolean booleanData = intent.getBooleanExtra(KEY, defaultValue);
char charData = intent.getCharExtra(KEY, defaultValue);
}
번들을 사용하여 한 활동에서 다른 활동으로 값을 전달할 수 있습니다. 현재 활동에서 번들을 작성하고 특정 값에 대한 번들을 설정하고 해당 번들을 의도로 전달하십시오.
Intent intent = new Intent(this,NewActivity.class);
Bundle bundle = new Bundle();
bundle.putString(key,value);
intent.putExtras(bundle);
startActivity(intent);
이제 NewActivity에서이 번들을 가져 와서 값을 검색 할 수 있습니다.
Bundle bundle = getArguments();
String value = bundle.getString(key);
의도를 통해 데이터를 전달할 수도 있습니다. 현재 활동에서 다음과 같이 의도를 설정하십시오.
Intent intent = new Intent(this,NewActivity.class);
intent.putExtra(key,value);
startActivity(intent);
이제 NewActivity에서 다음과 같은 의도로 그 가치를 얻을 수 있습니다.
String value = getIntent().getExtras().getString(key);
이것이 당신이하고있는 활동이라고 쓰십시오 :
Intent intent = new Intent(CurrentActivity.this,NextActivity.class);
intent.putExtras("string_name","string_to_pass");
startActivity(intent);
NextActivity.java에서
Intent getIntent = getIntent();
//call a TextView object to set the string to
TextView text = (TextView)findViewById(R.id.textview_id);
text.setText(getIntent.getStringExtra("string_name"));
이것은 나를 위해 작동합니다, 당신은 그것을 시도 할 수 있습니다.
첫 번째 활동 에서이 코드를 사용할 수 있습니다 .
Intent i = new Intent(Context, your second activity.class);
i.putExtra("key_value", "your object");
startActivity(i);
두 번째 활동 에서 객체를 얻습니다 .
Intent in = getIntent();
Bundle content = in.getExtras();
// check null
if (content != null) {
String content = content_search.getString("key_value");
}
참고 URL : https://stackoverflow.com/questions/768969/passing-a-bundle-on-startactivity
'Programming' 카테고리의 다른 글
연관 배열을 반복하고 키를 얻는 방법? (0) | 2020.06.02 |
---|---|
Pandas 데이터 프레임에서 특이 값 탐지 및 제외 (0) | 2020.06.02 |
누군가가 최대 절전 모드에서 MappingBy를 설명 할 수 있습니까? (0) | 2020.06.02 |
OSX의 Xcode를 최신 버전으로 어떻게 업데이트합니까? (0) | 2020.06.02 |
JAX-WS로 XML 요청 / 응답 추적 (0) | 2020.06.02 |