관리 메뉴

0101011001010111

입문 - 복습 / 액티비티 본문

Kotlin/[스스로]Kotlin&안드로이드

입문 - 복습 / 액티비티

[진주] 2023. 9. 4. 04:00
728x90
반응형

이전, 액티비티 공부 시 정리해뒀던 글

https://vjinjoov.tistory.com/61


액티비티 간의 연결 시, 

사용되는 명령어는 

SetContentView() 

 

 

 

 Manifests를 보자.

 

여기서 , application은 아래의 activity를 포함하고 있다는 말이다.

 

만약 여기에 액티비티를 몇개 더 추가한다 하면, 

 

이런식으로 추가가 될 것이고, 코드를 보면, 

이 부분에 추가가 될 것이다. 

 

 

작성되어 있는 activity 내의 intent-fliter를 보자면,

 

카테고리가 LAUNCHER로 줬다는 것은 

 

이 Application을 실행 시, 가장 먼저 해당 Activity가 실행된다는 의미이다.

 

 

 

만약 앱을 실행시킬 때, 가장 먼저 스플래시를 실행 시키려면 

스플래시 activity를 하나 만들고, 

거기다가 이 intent filter 에 LAUNCHER 값을 주게 되면, 

그 액티비티가 가장 먼저 선언이 되는 겁니다.

 

다른 액티비티가 아무리 많아도.

인텐트 필터에 런쳐값을 준 액티비티가 가장 먼저 실행 되게 됩니다.

 

 


 

Manifest의 역할

  • 애플리케이션 패키지 이름 (애플리케이션의 고유한 식별자 역할) 설정
  • 애플리케이션 구성요소들을 설명
  • 이 애플리케이션과 상호작용하는 다른 애플리케이션이 가져야할 권한 설정
  • 애플리케이션에서 사용하는 라이브러리 설정
  • 애플리케이션이 필요로 하는 Android API의 최소 수준 설정

 

 


 

전에했던 페이지가 3개인 앱을 만들어보자.

 

 

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <application
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.Test"
        tools:targetApi="31">
        <activity
            android:name=".SecondActivity"
            android:exported="false" />
        <activity
            android:name=".FirstActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

만드는 중 모르는 점 ▼

manifests에 보면, 

 

android:exported="false" 

해당 구문이 뭘 의미할까? 

 

 


android:exported 속성은,

해당 컴포넌트 (액티비티, 서비스, 리시버, 등)가 다른 앱에서 시작할 수 있는지 여부를 지정합니다.

android:exported="true": 이 컴포넌트는 다른 앱에서 시작할 수 있습니다.
android:exported="false": 이 컴포넌트는 오직 해당 앱 내부에서만 시작할 수 있습니다.


예를 들어, 

위의 매니페스트 파일에서 SecondActivity는 android:exported="false"로 설정되어 있으므로 

다른 앱에서는 이 액티비티를 직접 시작할 수 없습니다. 

 

반면에 FirstActivity는 android:exported="true"로 설정되어 있으므로 

다른 앱에서 이 액티비티를 시작하는 것이 가능합니다.

하지만 주의해야 할 것은, 

android:exported 속성이 명시적으로 설정되지 않았을 경우 

기본값은 <intent-filter>가 있으면 true, 없으면 false입니다. 

 

그래서,  android:exported를 명시적으로 false로 설정했다면 

intent-filter를 넣더라도 false라고 설정해 놓았기 때문에 true가 될 수 없다.

 


Android 12 (API 레벨 31)부터는 android:exported 속성의 명시적 선언이 필요하게 되었습니다.

 따라서 이 속성을 생략하면 컴파일 에러가 발생합니다.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

728x90
반응형