Start setting for activity alias

I set some alias for activity with different metadata.

In this metadata, I set the name of the fragment, which I then load with reflection.
I don’t know if this is a “clean” solution, although using the Snippets and putting the functionality inside, I had one SuperActivity and 2 Empty SubActivities to indicate each in the manifest.

The question now is: can I create an alias by intention? new Intent(Context, Class)will not work because I cannot find a way to set up metadata using an intentional call.

I need to run Intent using <activity android:name="XXX"/>, is there an easy way to do this?

General activity and its pseudonym, I need a new intention of the latter:

    <activity
        android:name="ActivityList"
        android:label="@string/app_name"
        android:launchMode="singleTop"
        android:screenOrientation="portrait" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

        <meta-data
            android:name="android.app.default_searchable"
            android:value="ActivityListItem" />
        <meta-data
            android:name="fragment"
            android:value="FragmentLocationList" />
    </activity>

    <activity-alias
        android:name="ActivityListItem"
        android:label="@string/locations"
        android:parentActivityName="ActivityList"
        android:targetActivity="ActivityList" >
        <intent-filter>
            <action android:name="android.intent.action.SEARCH" />
        </intent-filter>

        <meta-data
            android:name="android.app.searchable"
            android:resource="@xml/searchable" />
        <meta-data
            android:name="android.app.default_searchable"
            android:value="ActivityListItem" />
        <meta-data
            android:name="fragment"
            android:value="FragmentItemList" />
    </activity-alias>
+4
1

, setComponent(ComponentName) Intent().

,

<activity-alias
    android:name=".ActivityListItem"

( ), ComponentName ,

Intent intent = new Intent();
String packageName = context.getPackageName();
ComponentName componentName = new ComponentName(packageName,
                                                packageName + ".ActivityListItem");
intent.setComponent(componentName);
+16

Source: https://habr.com/ru/post/1529263/


All Articles