티스토리 뷰
Stack Overflow에 자주 검색, 등록되는 문제들과 제가 개발 중 찾아 본 문제들 중에서 나중에도 찾아 볼 것 같은 문제들을 정리하고 있습니다.
Stack Overflow에서 가장 먼저 확인하게 되는 가장 높은 점수를 받은 Solution과 현 시점에 도움이 될 수 있는 가장 최근에 업데이트(최소 점수 확보)된 Solution을 각각 정리하였습니다.
아래 word cloud를 통해 이번 포스팅의 주요 키워드를 미리 확인하세요.
How do I pass data between Activities in Android application?
안드로이드 애플리케이션에서 액티비티 사이에 데이터 전달하기
문제 내용
I have a scenario where, after logging in through a login page, there will be a sign-out button
on each activity
.
로그인 페이지를 통해 로그인한 후 각 액티비티에 로그아웃 버튼이 표시되는 시나리오가 있습니다.
On clicking sign-out
, I will be passing the session id
of the signed in user to sign-out. Can anyone guide me on how to keep session id
available to all activities
?
로그아웃을 클릭하면 로그인한 사용자의 세션 ID를 로그아웃으로 전달합니다. 세션 ID를 모든 액티비티에서 사용할 수 있도록 유지하는 방법을 가르쳐 줄 수 있는 사람이 있습니까?
Any alternative to this case
이 경우에 대한 어떤 대안이라도..
높은 점수를 받은 Solution
In your current Activity, create a new Intent
:
현재 액티비티에서 새 인텐트를 만듭니다.
String value="Hello world";
Intent i = new Intent(CurrentActivity.this, NewActivity.class);
i.putExtra("key",value);
startActivity(i);
Then in the new Activity, retrieve those values:
그런 다음 새 액티비티에서 다음 값을 검색합니다.
Bundle extras = getIntent().getExtras();
if (extras != null) {
String value = extras.getString("key");
//The key argument here must match that used in the other activity
}
Use this technique to pass variables from one Activity to the other.
이 방법을 사용하여 한 액티비티에서 다른 액티비티로 변수를 전달합니다.
가장 최근 달린 Solution
Best way to pass data to one Activity
to AnothetActivity
by using Intent
,
인텐트를 사용하여 하나의 액티비티에서 다른 액티비티에 데이터를 전달하는 가장 좋은 방법,
Check the code snipped
요약 코드를 확인하세요
ActivityOne.java
Intent myIntent = new Intent(this, NewActivity.class);
myIntent.putExtra("key_name_one", "Your Data value here");
myIntent.putExtra("key_name_two", "Your data value here");
startActivity(myIntent)
On Your SecondActivity
두 번째 액티비티에서..
SecondActivity.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view);
Intent intent = getIntent();
String valueOne = intent.getStringExtra("key_name_one");
String valueTwo = intent.getStringExtra("key_name_two");
}
출처 : https://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-in-android-application
'개발 > 안드로이드' 카테고리의 다른 글
URL을 클릭시 기본 브라우저 실행 문제 (0) | 2022.12.02 |
---|---|
어디에서나 어플리케이션 컨텍스트 사용하기 (0) | 2022.12.02 |
안드로이드 CalledFromWrongThreadException 수정하기 (0) | 2022.12.02 |
Android에서 화면 크기를 픽셀로 가져오는 방법 (0) | 2022.12.01 |
기본 앱을 사용하지 않고 JavaMail API로 이메일 보내기 (0) | 2022.12.01 |