Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Q (10) - The app icon is not displayed while the app is backgrounded in the stack of apps

QA team reported the bug on Pixel2 XL android Q (10) - The app icon is not displayed while the app is in background in the stack of apps (recents).

In the app used an adaptive icon created through 'Image Asset'. On previous Android versions - all good. But some times after the setup app through Google Play (or directly from an android studio) - app icon is not displayed when the app is backgrounded in the stack of apps. It happened not always.

wrong behavior

right behavior

For test was created default empty project with an adaptive icon (with legacy icons and icons for any dpi-v26). Bug reproduced. Also on the emulator with android 10.

In manifest:

<application
        android:icon="@mipmap/ic_launcher"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:allowBackup="false"
        android:supportsRtl="true">
    .....

Renaming app icons and other solutions don't help.

Update: I think it is a system bug. Because default apps like calendar have the same issues.

Thanks in advance!

like image 535
vicmikhailau Avatar asked Nov 08 '19 09:11

vicmikhailau


People also ask

How do you detect when an Android app goes to the background and come back to the foreground?

The onPause() and onResume() methods are called when the application is brought to the background and into the foreground again. However, they are also called when the application is started for the first time and before it is killed. You can read more in Activity.

What is foreground activity in Android?

Foreground services perform operations that are noticeable to the user. Foreground services show a status bar notification, so that users are actively aware that your app is performing a task in the foreground and is consuming system resources.

How do I know if an app is running in the background Android?

You can detect currently foreground/background application with ActivityManager. getRunningAppProcesses() which returns a list of RunningAppProcessInfo records. To determine if your application is on the foreground check RunningAppProcessInfo.


2 Answers

The issue because of somewhere else this icon exists which shown in your wrong behavior So just check is there any icon exists with wrong design which is.

Like in my case here two directories which contain icon with different background, So I am deleting the icon from this directory or otherwise, I delete this two directory and its work fine(Note: Don't delete directory go on explore and then delete.).

mipmap-anydpi-v26  
drawable-v24

enter image description here

like image 105
Dhaval Solanki Avatar answered Nov 10 '22 00:11

Dhaval Solanki


I had the same problem on real device, using Android 10 API level 29. Renaming the icons also did not fix it.

The solution I figured is to use new "adaptive icons". What this will basically do is generate adaptive icons which are not covered in the mimap folders. Use the following steps:

  1. Go to android/app/src/main/res/ folder of your project
  2. Create mipmap-anydpi-v26 folder if it does not exist.
  3. Create an xml file inside mipmap-anydpi-v26 folder. This xml file should be named exactly same as the string you are using for your icon name. For example, by default the name of icon string is ic_launcher, so name this xml as ic_launcher.xml.
  4. The xml should have the following lines, nothing else. You can paste these if you have made a new file in step 3. Make sure that you have _background and _foreground postfixes to the names as shown below. If you don't have these and just use @mipmap/ic_launcher for both background and foreground, it won't work.
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">  
    <background android:drawable="@mipmap/ic_launcher_background"/>
    <foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>
  1. Go to https://romannurik.github.io/AndroidAssetStudio/icons-launcher.html and first customize the background. I just used a white background. Before downloading, make sure that you name it as ic_launcher_background. Do the same for foreground using whatever image you need as foreground in icon and download it with the name ic_launcher_foreground.
  2. Extract the downloaded zip files, and copy the res folders one by one to android/app/src/main/res/.
  3. So now you should have 2 new files in each mimap folder with for foreground and background.
  4. Rebuild and run the project to see changes.
like image 33
CapeAndCowl Avatar answered Nov 10 '22 00:11

CapeAndCowl