programing

Android의 인 텐트 필터 란 무엇입니까?

projobs 2021. 1. 14. 08:01
반응형

Android의 인 텐트 필터 란 무엇입니까?


Android 앱에서 초기 활동 'A'에서 활동 'B'를 시작하고 싶었습니다. 이 두 가지에 대한 클래스를 만들었습니다. 그러나 다음 코드를 사용하여 B를 시작하면 런타임 오류가 발생 application has stopped unexpectedly, try again합니다.. 내 코드는 다음과 같습니다.

Intent myIntent = new Intent(this, AddNewActivity.class);
startActivity(myIntent); 

AndroidManifest.xml/manifest/application/activity/intent-filers활동 B 대한 새 항목을 추가 하면 응용 프로그램이 작동했습니다.

두 가지 질문이 있습니다.

  • 에 여러 활동 항목이있는 AndroidManifest.xml경우 Android는 먼저 시작할 활동을 어떻게 알 수 있습니까?
  • 인 텐트 필터를 이해할 수 없습니다. 누구든지 설명해 주시겠습니까?

여기 내 부분입니다 AndroidManifest.xml

<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".ListAllActivity"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".AddNewActivity" android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

AndroidManifest.xml에 여러 활동 항목이있는 경우 Android는 먼저 시작할 활동을 어떻게 알 수 있습니까?

"첫 번째"는 없습니다. 귀하의 경우에 표시된 것처럼 매니페스트를 사용하면 런처에 두 개의 아이콘이 있습니다. 사용자가 탭하는 것이 실행되는 것입니다.

인 텐트 필터를 이해할 수 없습니다. 누구든지 설명해 주시겠습니까?

주제에 대한 문서 가 꽤 많이 있습니다 . 그것을 읽고 더 구체적인 질문을하는 것을 고려하십시오.

또한 "애플리케이션이 예기치 않게 중지되었습니다. 다시 시도하십시오"라는 메시지가 표시되면 adb logcatEclipse에서, DDMS 또는 DDMS Perspective를 사용하여 오류와 연관된 Java 스택 추적을 조사하십시오.


인 텐트 필터는 구성 요소가 수신하려는 인 텐트 유형을 지정하는 앱 매니페스트 파일의 표현식입니다.

암시 적 인 텐트를 만들면 Android 시스템은 인 텐트의 콘텐츠를 기기에있는 다른 앱의 매니페스트 파일에 선언 된 인 텐트 필터와 비교하여 시작할 적절한 구성 요소를 찾습니다. 인 텐트가 인 텐트 필터와 일치하면 시스템이 해당 구성 요소를 시작하고 Intent 개체를 전달합니다.

AndroidManifest.xml

<activity android:name=".HelloWorld"
    android:label="@string/app_name">
    <intent-filter>
        <action android:name="android.intent.action.VIEW"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <category android:name="android.intent.category.BROWSABLE"/>
        <data android:scheme="http" android:host="androidium.org"/>
    </intent-filter>
</activity>

HelloWorld 시작

Intent intent = new Intent (Intent.ACTION_VIEW, Uri.parse("http://androidium.org"));
startActivity(intent);

먼저 xml을 변경하고 두 번째 활동을 DEFAULT로 표시하십시오.

<activity android:name=".AddNewActivity" android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

이제 StartActivity 메서드를 사용하여이 활동을 시작할 수 있습니다.


암시 적 인 텐트를 만들면 Android 시스템은 인 텐트의 콘텐츠를 기기에있는 다른 앱의 매니페스트 파일에 선언 된 인 텐트 필터와 비교하여 시작할 적절한 구성 요소를 찾습니다. 인 텐트가 인 텐트 필터와 일치하면 시스템이 해당 구성 요소를 시작하고 Intent 개체를 전달합니다. 여러 인 텐트 필터가 호환되는 경우 시스템은 사용자가 사용할 앱을 선택할 수 있도록 대화 상자를 표시합니다.

인 텐트 필터는 구성 요소가 수신하려는 인 텐트 유형을 지정하는 앱 매니페스트 파일의 표현식입니다. 예를 들어 활동에 대한 인 텐트 필터를 선언하면 다른 앱이 특정 종류의 인 텐트로 활동을 직접 시작할 수 있습니다. 마찬가지로 활동에 대한 인 텐트 필터를 선언하지 않으면 명시 적 인 텐트로만 시작할 수 있습니다.

According: Intents and Intent Filters


The Activity which you want it to be the very first screen if your app is opened, then mention it as LAUNCHER in the intent category and remaining activities mention Default in intent category.

For example :- There is 2 activity A and B
The activity A is LAUNCHER so make it as LAUNCHER in the intent Category and B is child for Activity A so make it as DEFAULT.

<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".ListAllActivity"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".AddNewActivity" android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
</application>

Keep the first intent filter with keys MAIN and LAUNCHER and add another as ANY_NAME and DEFAULT.

Your LAUNCHER will be activity A and DEFAULT will be your activity B.


There can be no two Lancher AFAIK. Logcat is a usefull tool to debug and check application/machine status in the behind. it will be automatic while switching from one activity to another activity.


intent filter is expression which present in manifest in your app that specify the type of intents that the component is to receive. If component does not have any intent filter it can receive explicit intent. If component with filter then receive both implicit and explicit intent


If possible try this one instant solution:

Intent intent =new Intent(getApplicationBaseContext,second_Act.class);
StartActivity(intent);

ReferenceURL : https://stackoverflow.com/questions/3321514/what-are-intent-filters-in-android

반응형