Android Application

Kotlin 인텐트(intent) : 명시적 인텐트와 암시적 인텐트 테스트 예제

작성자 임베디드코리아 작성일23-10-23 22:58 조회1,556회 댓글0건

첨부파일

Kotlin 인텐트(intent) : 명시작 인텐트와 암시적 인텐트 테스트 예제

-------------------------------------------------------------------------------------
      activity_main.xml
-------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#E1DCB0">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text=" 여기는 \n 명시적 Activity \n 입니다."
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/btnClose"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Go Back"
        android:layout_marginBottom="20dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

-------------------------------------------------------------------------------------
**>>      left_btn_backgound.xml
* res/drawable 에서 오른쪽 마우스
* New --> Drawable Resoure File          File name : left_btn_backgound    Root element : shape
-------------------------------------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid
        android:color="#FFFFFF"/>
    <stroke
        android:width="2dp"
        android:color="#0A64BE" />
    <size
        android:width="200dp"
        android:height="36dp" />
    <corners android:bottomLeftRadius="10dp"
        android:topLeftRadius="10dp"/>
</shape>

-------------------------------------------------------------------------------------
**>>      right_btn_backgound.xml
* res/drawable 에서 오른쪽 마우스
* New --> Drawable Resoure File          File name : right_btn_backgound    Root element : shape
-------------------------------------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid
        android:color="#CCCCCC"/>
    <stroke
        android:width="3dp"
        android:color="#0A64BE" />
    <size
        android:width="200dp"
        android:height="36dp" />
    <corners android:bottomRightRadius="10dp"
        android:topRightRadius="10dp"/>
</shape>

-------------------------------------------------------------------------------------
**>>      icon.xml
* res/drawable 에서 오른쪽 마우스
* New --> Drawable Resoure File          File name : icon    Root element : layer-list
-------------------------------------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:drawable="@drawable/ic_android_black_24dp"
        android:width="30dp"
        android:height="30dp"/>
</layer-list>

-------------------------------------------------------------------------------------
**>>    ic_android_black_24dp.xml
* res/drawable 에서 오른쪽 마우스
* New --> Vector Asset          Nameame : ic_android_block_24dp
-------------------------------------------------------------------------------------------------------------------------------


-------------------------------------------------------------------------------------
*****      activity_explicit.xml **
--- res/layout 에서  ---> New  --> Layout Resource File
--- File : activity_explicit  ,  Source set : main
-------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#E1DCB0">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text=" 여기는 \n 명시적 Activity \n 입니다."
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/btnClose"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Go Back"
        android:layout_marginBottom="20dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>


-------------------------------------------------------------------------------------
*****      activity_impricit.xml **
--- res/layout 에서  ---> New  --> Layout Resource File
--- File : activity_impricitt  ,  Source set : main
-------------------------------------------------------------------------------------
<?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"
    android:background="#CDEAED"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/reciveData"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text=" 여기는 \n 암시적 Activity \n 입니다."
        android:layout_marginTop="30dp"/>

    <Button
        android:id="@+id/ReturnBTN"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:text="돌아가기" />
</LinearLayout>

------------------------------------------------------------------------------------
    AndroidManifest.xml
------------------------------------------------------------------------------------
>>> 추가하기

      <activity
            android:name=".ExplicitActivity" >
        </activity>
        <activity
            android:name=".ImplicitActivity"
            android:exported="true" >
            <intent-filter>
                <action android:name="intent.implicit.second" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

------------------------------------------------------------------------------------
    themes.xml
------------------------------------------------------------------------------------
<resources xmlns:tools="http://schemas.android.com/tools">
    <!-- Base application theme. -->
    <style name="Base.Theme.IntentExplicitImplicit" parent="Theme.AppCompat.Light">
        <item name="colorPrimaryDark">#3F51B5</item>
        <item name="colorPrimary">#4CAF50</item>

    </style>

    <style name="Theme.IntentExplicitImplicit" parent="Base.Theme.IntentExplicitImplicit" />
</resources>