반응형

Explicit Intent인텐트를 충족하는 애플리케이션이 무엇인지 지정합니다. 이를 위해 대상 앱의 패키지 이름 또는 완전히 자격을 갖춘 구성 요소 클래스 이름을 제공.

 

ex) Page1에서 Page2로 넘어갈 때, 사용되는 노드 같은 것

 

 

0. AndroidManifest.xml ( SecondActivty를 manifest에 추가 )

        <activity android:name=".SecondActivity">

        </activity>

 

 

1. first_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button"
        android:onClick="ClickButton"
        android:id="@+id/btn">

    </Button>

</LinearLayout>

2. MainActivity.java (Activity A)

package com.example.project8_intent;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.first_layout);
		
        // Button Event
        Button btn = (Button)findViewById(R.id.btn);
        btn.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view)
            {
                // intent ( Start Point : Main -> End Point : SecondActivity )
                Intent intent = new Intent(getApplicationContext(), SecondActivity.class);
                startActivity(intent);
            }
        });
    }
}

 Button Click했을 때( Start Point : MainActivity ---> End Point : SecondActivity )

 

 

 

3. second_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Second Button"
        android:id="@+id/btn2"
        >

    </Button>

</LinearLayout>

4. SecondActivity.java

package com.example.project8_intent;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public class SecondActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.second_layout);

        Button btn = (Button)findViewById(R.id.btn2);
		
        // SecondActivity 종료
        btn.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view){
                finish();

            }
        });
    }
}

 Button Click했을 때( SecondActivity 종료)

 

 

MainActvity.java
SecondActivty

 

developer.android.com/guide/components/intents-filters?hl=ko#java

 

인텐트 및 인텐트 필터  |  Android 개발자  |  Android Developers

An Intent is a messaging object you can use to request an action from another app component . Although intents facilitate communication between components in several ways, there are three fundamental use cases: An Activity represents a single screen in…

developer.android.com

 

728x90
반응형

+ Recent posts