【问题标题】:After the app icon and app name changed programatically, then after minimizing the app the application not found in background在应用程序图标和应用程序名称以编程方式更改后,在最小化应用程序后,在后台找不到应用程序
【发布时间】:2020-04-03 07:07:28
【问题描述】:

在 android kotlin 中,我使用活动别名概念更改了应用程序图标和应用程序名称。但是在切换图标和应用程序名称之后。当应用程序最小化时,在我的后台找不到该应用程序。 附上问题参考视频链接:https://drive.google.com/file/d/1V59pBDjhC6kvK5uvnRH3Miqd291pbN2g/view?usp=sharing

我的 Mainactivity.kt 和 android.xml 代码如下:

  packageManager.setComponentEnabledSetting(ComponentName("com.example.batpoc","com.example.batpoc.MainActivityOneLaunch"), PackageManager.COMPONENT_ENABLED_STATE_ENABLED,PackageManager.DONT_KILL_APP)
    packageManager.setComponentEnabledSetting(ComponentName("com.example.batpoc","com.example.batpoc.MainActivity"), PackageManager.COMPONENT_ENABLED_STATE_DISABLED,PackageManager.DONT_KILL_APP)




<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.batpoc">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
     calls FlutterMain.startInitialization(this); in its onCreate method.
     In most cases you can leave this as-is, but you if you want to provide
     additional functionality it is fine to subclass or reimplement
     FlutterApplication and put your custom class here. -->
<application
    android:name="io.flutter.app.FlutterApplication"
    android:label="batpoc"
    android:icon="@mipmap/ic_launcher">
    <activity
        android:name=".MainActivity"
        android:launchMode="singleTop"        
        android:theme="@style/LaunchTheme"
        android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
        android:hardwareAccelerated="true"
        android:windowSoftInputMode="adjustResize">
          <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
      <activity-alias
            android:name=".MainActivityOneLaunch"
            android:enabled="false"
            android:roundIcon="@mipmap/th"
            android:icon="@mipmap/th"
            android:label="One Launch"
            android:targetActivity=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
             <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity-alias>

</application>

请指导。提前致谢。

【问题讨论】:

    标签: android flutter kotlin dart


    【解决方案1】:

    在Manifest.xml中创建这样的配置

    <activity android:name="package.name.MainActivity"
     android:screenOrientation="portrait"
     android:label="@string/app_name"
     android:theme="@style/CustomTheme"
     android:launchMode="singleTask">
      <intent-filter>
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
    
    <activity-alias android:label="@string/app_name_default" 
     android:icon="@drawable/icon_default" 
     android:name=".MainActivity-Default"
     android:enabled="true"
     android:targetActivity=".MainActivity">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>   
    </activity-alias>
    
    <activity-alias android:label="@string/app_name_flavor_one" 
     android:icon="@drawable/icon_flavor_one" 
     android:name=".MainActivity-Flavor-One"
     android:enabled="false"
     android:targetActivity=".MainActivity">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>   
    </activity-alias>
    

    现在您可以在这两个别名之间切换,因此我们将更改应用图标或/和名称。要从 Default 切换到 Flavor-One,请使用此代码。

    getPackageManager().setComponentEnabledSetting(
        new ComponentName("package.name", "package.name.MainActivity-Flavor-One"), 
            PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
     getPackageManager().setComponentEnabledSetting(
        new ComponentName("package.name", "package.name.MainActivity-Default"), 
            PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
    

    请记住,您必须跟踪一次只能启用一个别名

    【讨论】:

      猜你喜欢
      • 2016-04-21
      • 2021-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-13
      • 1970-01-01
      相关资源
      最近更新 更多