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

我已经开发了一个新版本的应用程序,我已经更改了已启动的活动的名称.

在升级之前,清单中有:

    <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
              android:name=".view.SplashActivity"
              ... >
                    ...
    </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.

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

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>在清单中指定新的启动器活动.这样,当用户点击启动器图标时,您的新活动就会启动.

上一篇:Mac M1 Silicon docker编译(解决no matching manifest for linux/arm64/v8)


下一篇:是否可以在java Manifest文件中使用SHA1-Digest而无需实际使用密钥