티스토리 뷰
반응형
Stack Overflow에 자주 검색, 등록되는 문제들과 제가 개발 중 찾아 본 문제들 중에서 나중에도 찾아 볼 것 같은 문제들을 정리하고 있습니다.
Stack Overflow에서 가장 먼저 확인하게 되는 가장 높은 점수를 받은 Solution과 현 시점에 도움이 될 수 있는 가장 최근에 업데이트(최소 점수 확보)된 Solution을 각각 정리하였습니다.
아래 word cloud를 통해 이번 포스팅의 주요 키워드를 미리 확인하세요.
How to start new activity on button click
버튼 클릭 시 새로운 액티비티를 시작하는 방법
문제 내용
In an Android application, how do you start a new activity (GUI) when a button in another activity is clicked, and how do you pass data between these two activities?
Android 응용 프로그램에서 다른 액티비티의 버튼을 클릭할 때 새 액티비티(GUI)를 시작하는 방법과 이 두 액티비티 사이에 데이터를 전달하는 방법은 무엇입니까?
높은 점수를 받은 Solution
Easy.
쉽습니다. putExtra를 통해 추가 정보를 전달 할 수 있습니다.
Intent myIntent = new Intent(CurrentActivity.this, NextActivity.class);
myIntent.putExtra("key", value); //Optional parameters
CurrentActivity.this.startActivity(myIntent);
Extras are retrieved on the other side via:
다른 쪽에서는 다음을 통해 추가 정보를 가져올 수 있습니다.
@Override
protected void onCreate(Bundle savedInstanceState) {
Intent intent = getIntent();
String value = intent.getStringExtra("key"); //if it's a string you stored.
}
Don't forget to add your new activity in the AndroidManifest.xml:
Android Manifest.xml에 새 액티비티를 추가하는 것을 잊지 마십시오.
<activity android:label="@string/app_name" android:name="NextActivity"/>
가장 최근 달린 Solution
Button button = findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(SplashActivity.this,HomeActivity.class);
startActivity(intent);
}
});
출처 : https://stackoverflow.com/questions/4186021/how-to-start-new-activity-on-button-click
반응형
'개발 > 안드로이드' 카테고리의 다른 글
안드로이드 웹뷰의 캐시 완전히 지우기 (0) | 2022.12.19 |
---|---|
Android에서 문자열을 Uri로 바꾸기 (0) | 2022.12.18 |
컨텍스트로 레이아웃 인플레이터 가져오기 (0) | 2022.12.18 |
웹뷰로 외부 웹 페이지 로드하기 (0) | 2022.12.18 |
'Error retrieving parent for item' 오류 수정하기 (0) | 2022.12.18 |
댓글
공지사항
최근에 올라온 글