gpt4 book ai didi

android - 在新的应用程序版本中更改启动器 Activity 名称

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:31:54 26 4
gpt4 key购买 nike

我开发了一个新版本的应用程序,并且更改了启动的 Activity 的名称。

升级前, list 中是:

    <activity
android:name=".Splash"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

然后我只更改了 Activity 的名称和包,现在是:

    <activity
android:name=".view.SplashActivity"
... >
...
</activity>

发生的情况是人们从市场下载应用程序后,启动器没有刷新,它仍然调用旧的 Activity 路径。

你知道怎么解决吗?

最佳答案

引用Things That Cannot Change

它说,

A subtle but important aspect of what constitutes a break in compatibility is the android:name attribute of your activity, service, and receiver components. This can be surprising because we think of android:name as pointing to the private code implementing our application, but it is also (in combination with the manifest package name) the official unique public name for that component, as represented by the ComponentName class.

Changing the component name inside of an application can have negative consequences for your users. Some examples are:

  • If the name of a main activity of your application is changed, any shortcuts the user made to it will no longer work. A shortcut is an Intent that directly specifies the ComponentName it should run.
  • If the name of a service implementing a Live Wallpaper changes, then a user who has enabled your Live Wallpaper will have their wallpaper revert to the system default when getting the new version of your app. The same is true for Input Methods, Accessibility Services, Honeycomb’s new advanced Widgets, and so on.
  • If the name of a receiver implementing a Device Admin changes, then as with the live wallpaper example, the device admin will be disabled when the application is updated. This also applies to other kinds of receivers, such as App Widgets.

因此,如果可能,请不要更改 list 中声明的​​组件名称,或使用以下代码删除指向该组件的任何图标。

ComponentName componentToDisable = new ComponentName("application.package.name", "packagename.ActivityClassName");
getPackageManager().setComponentEnabledSetting(componentToDisable, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

还使用 <intent-filter>...</intent-filter> 在 list 中指定新的启动器 Activity 这样您的新 Activity 就会在用户单击启动器图标时启动。

关于android - 在新的应用程序版本中更改启动器 Activity 名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9433855/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com