Skip to main content
Question

Android AppInBackground is always true even when app is at foreground


Forum|alt.badge.img+6

Hi, I’m using the latest version of RevenueCat SDK on Android 5.7.1. I’ve noticed in debug logs that `AppInBackground` is always `true` even through the app is at foreground.

This has caused some issues, such as cache not being updated in time. IIUC if app is in background, the SDK only updates cache once a day instead of the default 5 mins. Also, I realise that offerings are not being cached at app launch. When I start the activity with paywall, there’s always a noticeably delay of 2-3s to fetch the offerings. I’m not sure if this is related to `AppInBackground` always being `true`.

 

Here’s a complete list of debug logs when I open the app

```

2023-02-14 01:15:11.298 30603-30603 [Purchases] - DEBUG     com.yygg.note.app                    D  ℹ️ Debug logging enabled
2023-02-14 01:15:11.298 30603-30603 [Purchases] - DEBUG     com.yygg.note.app                    D  ℹ️ SDK Version - 5.7.1
2023-02-14 01:15:11.298 30603-30603 [Purchases] - DEBUG     com.yygg.note.app                    D  ℹ️ Package name - com.yygg.note.app
2023-02-14 01:15:11.298 30603-30603 [Purchases] - DEBUG     com.yygg.note.app                    D  👤 Initial App User ID - null
2023-02-14 01:15:11.298 30603-30603 [Purchases] - DEBUG     com.yygg.note.app                    D  👤 Identifying App User ID: de95dfef-476b-488c-8ea3-a9134e3436a3
2023-02-14 01:15:11.299 30603-30603 [Purchases] - DEBUG     com.yygg.note.app                    D  ℹ️ Deleting old synced subscriber attributes that don't belong to de95dfef-476b-488c-8ea3-a9134e3436a3
2023-02-14 01:15:11.640 30603-30603 [Purchases] - DEBUG     com.yygg.note.app                    D  ℹ️ Starting connection for com.android.billingclient.api.BillingClientImpl@23048b3
2023-02-14 01:15:11.909 30603-30603 [Purchases] - DEBUG     com.yygg.note.app                    D  ℹ️ Billing Service Setup finished for com.android.billingclient.api.BillingClientImpl@23048b3
2023-02-14 01:15:11.909 30603-30603 [Purchases] - DEBUG     com.yygg.note.app                    D  ℹ️ Updating pending purchase queue
2023-02-14 01:15:11.916 30603-30728 [Purchases] - DEBUG     com.yygg.note.app                    D  ℹ️ Querying purchases
2023-02-14 01:15:11.932 30603-30735 [Purchases] - DEBUG     com.yygg.note.app                    D  ℹ️ Cleaning previously sent tokens
2023-02-14 01:15:11.932 30603-30735 [Purchases] - DEBUG     com.yygg.note.app                    D  ℹ️ Tokens already posted: []
2023-02-14 01:15:11.932 30603-30735 [Purchases] - DEBUG     com.yygg.note.app                    D  ℹ️ Saving tokens []
2023-02-14 01:15:11.933 30603-30735 [Purchases] - DEBUG     com.yygg.note.app                    D  ℹ️ Tokens already posted: []
2023-02-14 01:15:12.144 30603-30705 [Purchases] - DEBUG     com.yygg.note.app                    D  Retrieving customer info with policy: CACHED_OR_FETCHED
2023-02-14 01:15:12.148 30603-30705 [Purchases] - DEBUG     com.yygg.note.app                    D  ℹ️ Vending CustomerInfo from cache.
2023-02-14 01:15:12.148 30603-30705 [Purchases] - DEBUG     com.yygg.note.app                    D  ℹ️ Checking if cache is stale AppInBackground true
2023-02-14 01:15:12.149 30603-30687 [Purchases] - DEBUG     com.yygg.note.app                    D  Retrieving customer info with policy: CACHED_OR_FETCHED
2023-02-14 01:15:12.150 30603-30687 [Purchases] - DEBUG     com.yygg.note.app                    D  ℹ️ Vending CustomerInfo from cache.
2023-02-14 01:15:12.150 30603-30687 [Purchases] - DEBUG     com.yygg.note.app                    D  ℹ️ Checking if cache is stale AppInBackground true
2023-02-14 01:15:12.151 30603-30603 [Purchases] - DEBUG     com.yygg.note.app                    D  ℹ️ setEmail called
2023-02-14 01:15:12.152 30603-30693 [Purchases] - DEBUG     com.yygg.note.app                    D  Retrieving customer info with policy: CACHED_OR_FETCHED
2023-02-14 01:15:12.153 30603-30693 [Purchases] - DEBUG     com.yygg.note.app                    D  ℹ️ Vending CustomerInfo from cache.
2023-02-14 01:15:12.153 30603-30693 [Purchases] - DEBUG     com.yygg.note.app                    D  ℹ️ Checking if cache is stale AppInBackground true
2023-02-14 01:15:12.172 30603-30705 [Purchases] - DEBUG     com.yygg.note.app                    D  Retrieving customer info with policy: CACHED_OR_FETCHED
2023-02-14 01:15:12.173 30603-30705 [Purchases] - DEBUG     com.yygg.note.app                    D  ℹ️ Vending CustomerInfo from cache.
2023-02-14 01:15:12.174 30603-30705 [Purchases] - DEBUG     com.yygg.note.app                    D  ℹ️ Checking if cache is stale AppInBackground true
2023-02-14 01:15:59.850 30603-30694 [Purchases] - DEBUG     com.yygg.note.app                    D  Retrieving customer info with policy: CACHED_OR_FETCHED
2023-02-14 01:15:59.851 30603-30693 [Purchases] - DEBUG     com.yygg.note.app                    D  Retrieving customer info with policy: CACHED_OR_FETCHED
2023-02-14 01:15:59.854 30603-30693 [Purchases] - DEBUG     com.yygg.note.app                    D  ℹ️ Vending CustomerInfo from cache.
2023-02-14 01:15:59.854 30603-30694 [Purchases] - DEBUG     com.yygg.note.app                    D  ℹ️ Vending CustomerInfo from cache.
2023-02-14 01:15:59.854 30603-30693 [Purchases] - DEBUG     com.yygg.note.app                    D  ℹ️ Checking if cache is stale AppInBackground true
2023-02-14 01:15:59.854 30603-30694 [Purchases] - DEBUG     com.yygg.note.app                    D  ℹ️ Checking if cache is stale AppInBackground true

```

8 replies

cody
RevenueCat Staff
Forum|alt.badge.img+8
  • RevenueCat Staff
  • 492 replies
  • February 15, 2023

Hey @william_O,

Thanks for the report - something definitely seems off here. Can you trying backgrounding the app, then foregrounding again and seeing if that toggle works? Trying to figure out what might be causing it, from there we’ll continue investigating.

Were you by chance using an older version of the SDK at some point that wasn’t exhibiting this behavior?


Forum|alt.badge.img+6
  • Author
  • Member
  • 7 replies
  • February 16, 2023

Also, this is my first time integrating the RevenueCat library, so I’ve been using the latest 5.7.1 version since the beginning.


Forum|alt.badge.img+6
  • Author
  • Member
  • 7 replies
  • February 22, 2023

Not sure where my previous comment goes, I’ve replied three comments with debug logs but it says “comment will be shown after someone approves”, 5 days later yet the comment is not shown here.

 

Basically I’ve tried backgrounding the app and then foregrounding it, however, the `AppInBackground` attribute is always true.


Forum|alt.badge.img+6
  • Author
  • Member
  • 7 replies
  • February 22, 2023

Friendly ping on this issue, as this has made our integration and testing with the RevenueCat library extremely difficult


Forum|alt.badge.img+6
  • Author
  • Member
  • 7 replies
  • March 2, 2023
cody wrote:

Hey @william_O,

Thanks for the report - something definitely seems off here. Can you trying backgrounding the app, then foregrounding again and seeing if that toggle works? Trying to figure out what might be causing it, from there we’ll continue investigating.

Were you by chance using an older version of the SDK at some point that wasn’t exhibiting this behavior?

Hello, any updates here?


Forum|alt.badge.img+6
  • Author
  • Member
  • 7 replies
  • March 2, 2023

cody
RevenueCat Staff
Forum|alt.badge.img+8
  • RevenueCat Staff
  • 492 replies
  • March 13, 2023

Hey @william_O,

Apologies for the delay here. Would you be willing to open a support ticket here so we can investigate further?


Cesar
RevenueCat Staff
Forum|alt.badge.img+3
  • RevenueCat Staff
  • 63 replies
  • August 21, 2024

Another developer was facing the same issue in 


The issue was a custom WorkManager initialisation. They solved it by making sure the AndroidManifest was only removing the WorkManagerInitializer node:
 

 <provider
    android:name="androidx.startup.InitializationProvider"
    android:authorities="${applicationId}.androidx-startup"
    android:exported="false"
    tools:node="merge">
    <!-- If you are using androidx.startup to initialize other components -->
    <meta-data
        android:name="androidx.work.WorkManagerInitializer"
        android:value="androidx.startup"
        tools:node="remove" />
 </provider>


Just in case it helps someone else facing this issue


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings