이 바보 같은 질문이지만, 내가 많이 검색하고 난인수 전달 /의 매개 변수 안드로이드
나는 완전히이 코드를 이해 해달라고 아무것도 찾을 수 있다면 죄송합니다 -
Intent intent = new Intent (this, MainActivity.class)
무엇 그 라인에 대해 이해가 안되는 부분은 (this, MainActivity.class)
입니다. 누군가 설명해 주겠습니까?
감사합니다.
이 바보 같은 질문이지만, 내가 많이 검색하고 난인수 전달 /의 매개 변수 안드로이드
나는 완전히이 코드를 이해 해달라고 아무것도 찾을 수 있다면 죄송합니다 -
Intent intent = new Intent (this, MainActivity.class)
무엇 그 라인에 대해 이해가 안되는 부분은 (this, MainActivity.class)
입니다. 누군가 설명해 주겠습니까?
감사합니다.
그것은 잘 here을 문서화 :
public Intent (Context packageContext, Class<?> cls)
Since: API Level 1
Create an intent for a specific component. All other fields (action, data, type, class) are null, though they can be modified later with explicit calls. This provides a convenient way to create an intent that is intended to execute a hard-coded class name, rather than relying on the system to find an appropriate class for you; see setComponent(ComponentName) for more information on the repercussions of this.
Parameters
packageContext A Context of the application package implementing this class.
cls The component class that is to be used for the intent.
인수를 문맥과 클래스 될 것이다이 경우 의도에 대해.
컨텍스트는 기본적으로 프로그램이 표시되는 내용과 리소스의 위치를 추적 할 수있는 안드로이드 시스템의 환상적인 부분입니다. 어떤면에서는 다른 시스템의 시스템과 같은 것으로 간주 할 수 있습니다. 많은 것들이 느슨하게 결합 된 특성을 가지고 모든 것이 작동하도록 보장하기 위해 상황을 필요로합니다.
필요한 것 클래스는 된 .java의 컴파일 된 버전이 사용하여 개체를 인스턴스화 유사한 것으로 활동을 시작하는 인 텐트를 사용하는 과정의 MainActivity.Class
생각해을 통과 할 MainActivity.java을 실행할 수 있도록 파일입니다 Java new
키워드입니다. 예 ...
MyClass.java
다른 코드에서public class MyClass {
}
... 안드로이드 활동에
MyClass exampleClass = new MyClass();
는 본질적으로 단순히 자바 클래스입니다 - 그들은, 그러나, '특별'클래스를 사용하므로 인스턴스화시 new
을 사용하지 않습니다. 대신 우리는 안드로이드 시스템에 우리를 위해 인스턴스화하도록 요청합니다. 당신이주는 예에서
MainActivity.java
public class MainActivity extends Activity {
}
그런 인스턴스화하는 활동 클래스를 명시 적으로 정의하는 ...
Intent intent = new Intent (this, MainActivity.class);
startActivity(intent);
startActivity(...)
에 대한 호출은 '새로운'을 인스턴스화하는 안드로이드 시스템을 묻는 방법입니다 MainActivity 인스턴스
다른 게시물에서 언급했듯이이 방법은 안드로이드 Context
(이 경우 this
을 사용)을 통과해야합니다. 즉, MainActivity
의 새 인스턴스를 생성하도록 요청하는 응용 프로그램 구성 요소가 자신을 Context
으로 전달하고 있음을 의미합니다.
제목과 질문이 서로 어떤 관련이 있는지 잘 모르겠습니다. 새로운 Intent (this, MainActivity.class)가 'this'Activity에서 MainActivity ... Activity를로드합니다. 인수 인수에 관한 질문은 무엇입니까? – CrackerJack9