What to put as launcher:ClassName for launcher favorite

感情迁移 提交于 2019-12-20 07:32:03

问题


My client wants to put the app I developed to be in their launcher favorite and they are asking for the package name and class name of the launcher. Package name is quite straightforward, but ClassName isn't since if I look into the manifest the class name is preceeded by a hash like this: md599e473470f20dc18f556aff51bcfbcb1.LaunchScreen

So what is the class name I have to use for launcher favorite, the whole thing or only the class name LaunchScreen?

Thanks


回答1:


(Congrats on getting into their favorites, should you provide a Play link ;-)

As you say, the package name is easy, it is the defined in the manifest as a package attribute of the manifest element:

<manifest .... package="com.sushihangover.playscriptstarling2" ...>

The launcher class name is the class that is tagged within the Activity C# class attribute, "MainLauncher = true"

In turn, this creates the activity attribute fragment within the manifest:

<activity android:icon="@mipmap/icon" android:label="PlayScriptStarling2" android:name="md5d2519388ea1895e3e3594794d2e0c4ce.MainActivity">
  <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
</activity>

Your class name is the full android:name attribute since it does NOT begin with a period. This is a generated unique subclass identifier, thus in my example this is the full class name:

md5d2519388ea1895e3e3594794d2e0c4ce.MainActivity

While most people will never see this class ID, I highly recommend you override this generate class identifier and use the dot class notation that includes your package name.

Normally, this is done by providing a name using the android:name that BEGINS with a period (this is standard Android class naming 101 ;-) but Xamarin currently does not support Android shorthand-style class names beginning w/ a dot so you need to use the fully qualified package name with your class ID name.

So the Main Activity attribute becomes:

[Activity(Label = "PlayScriptStarling2", Name = "com.sushihangover.playscriptstarling2.MyBigBadGameEveryOneShouldPlay", MainLauncher = true, Icon = "@mipmap/icon")]

And the generated manifest becomes:

<activity android:icon="@mipmap/icon" android:label="PlayScriptStarling2" android:name="com.sushihangover.playscriptstarling2.MyBigBadGameEveryOneShouldPlay">
  <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
</activity>

And my launcher class name becomes:

com.sushihangover.playscriptstarling2.MyBigBadGameEveryOneShouldPlay

Android Docs:

Declaring class names

Many elements correspond to Java objects, including elements for the application itself (the element) and its principal components — activities (), services (), broadcast receivers (), and content providers ().

If you define a subclass, as you almost always would for the component classes (Activity, Service, BroadcastReceiver, and ContentProvider), the subclass is declared through a name attribute. The name must include the full package designation. For example, an Service subclass might be declared as follows:

<manifest . . . >
    <application . . . >
        <service android:name="com.example.project.SecretService" . . . >
            . . .
        </service>
        . . .
    </application>
</manifest>

However, as a shorthand, if the first character of the string is a period, the string is appended to the application's package name (as specified by the element's package attribute).

The following assignment is the same as the one above:

<manifest package="com.example.project" . . . >
    <application . . . >
        <service android:name=".SecretService" . . . >
            . . .
        </service>
        . . .
    </application>
</manifest>

When starting a component, Android creates an instance of the named subclass. If a subclass isn't specified, it creates an instance of the base class.

Ref: http://developer.android.com/guide/topics/manifest/manifest-intro.html

Ref: https://developer.xamarin.com/guides/android/advanced_topics/working_with_androidmanifest.xml/#Intent_Actions_and_Features



来源:https://stackoverflow.com/questions/36470399/what-to-put-as-launcherclassname-for-launcher-favorite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!