티스토리 뷰
Stack Overflow에 자주 검색, 등록되는 문제들과 제가 개발 중 찾아 본 문제들 중에서 나중에도 찾아 볼 것 같은 문제들을 정리하고 있습니다.
Stack Overflow에서 가장 먼저 확인하게 되는 가장 높은 점수를 받은 Solution과 현 시점에 도움이 될 수 있는 가장 최근에 업데이트(최소 점수 확보)된 Solution을 각각 정리하였습니다.
아래 word cloud를 통해 이번 포스팅의 주요 키워드를 미리 확인하세요.
Using Intent in an Android application to show another activity
안드로이드 애플리케이션에서 다른 액티비티를 보여주기 위해 인텐트를 사용하기
문제 내용
In my Android application, I have two activity classes. I have a button on the first one and I want to show the second when it is clicked, but I get an error. Here are the classes:
저의 안드로이드 애플리케이션에서는 두 개의 액티비티 클래스가 있습니다. 첫 번째 액티비티에 버튼이 있으며, 버튼을 클릭하면 두 번째 액티비티를 표시하려고 합니다. 그러나 오류가 발생합니다. 클래스는 다음과 같습니다:
public class FirstActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button orderButton = (Button)findViewById(R.id.order);
orderButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(FirstActivity.this, OrderScreen.class);
startActivity(intent);
}
});
}
}
The second class that should show when the button is clicked, but never does:
버튼을 클릭할 때 나와야 할 두 번째 클래스인데, 나타나지 않습니다.
public class OrderScreen extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.order);
Button orderButton = (Button) findViewById(R.id.end);
orderButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
});
}
}
How do I create a button that will show the second activity?
두 번째 액티비티를 표시할 버튼을 어떻게 만드는지 알고 싶습니다.
높은 점수를 받은 Solution
The issue was the OrderScreen Activity
wasn't added to the AndroidManifest.xml. Once I added that as an application node, it worked properly.
이 문제는 OrderScreen Activity가 AndroidManifest.xml에 추가되지 않았기 때문입니다. 애플리케이션 노드로 추가하면 제대로 작동합니다.
<activity android:name=".OrderScreen" />
가장 최근 달린 Solution
<activity android:name="[packagename optional].ActivityClassName"></activity>
Simply adding the activity which we want to switch to should be placed in the manifest file
단순히 전환하려는 액티비티를 추가하기 위해서는 매니페스트 파일에 위치시켜야 합니다.
출처 : https://stackoverflow.com/questions/736571/using-intent-in-an-android-application-to-show-another-activity
'개발 > 안드로이드' 카테고리의 다른 글
안드로이드에서 전역 변수 만드는 방법 (0) | 2023.02.06 |
---|---|
Android WebView가 HTTPS URL을 로드 못하는 문제 수정하기 (0) | 2023.02.06 |
WebView 데이터 로드 후 스크롤뷰가 스크롤되는 문제 수정하기 (0) | 2023.02.05 |
EditText를 둥근 모서리로 만들기 (0) | 2023.02.05 |
Glide를 사용하여 이미지를 비트맵으로 다운로드하기 (0) | 2023.02.05 |