Android Question why app power consumption still increase when app close or background on android 10?

Maodge

Member
Licensed User
hello,
I create a ads test project using firebaseAdmob lib.
and test it on Honor BKK-AL10 and Redmi 9A.

I found that the power consumption of the same porject on two devices is different.

On Honor BKK-AL10 android 8.1.0, when the app is switched to the background or manually close or removed from the recent list, it is detected in the battery interface that the power consumption basically does not increase. power consumption datashow in pic001 pic002, It consumption about 0.6mAh in 30 min.


On Redmi 9A android 10, when the app is switched to the background or manually close or removed from the recent list, it is detected in the battery interface that the power consumption is still increased. It consumption about 80mAh in an hour when the app in background or manually close or removed from the recent list. power consumption data --- pic 003

so why? how can I reduce it on android 10?

my project code:
MAIN.B4A:
#Region  Project Attributes
    #ApplicationLabel: test bat v4
    #VersionCode: 777
    #VersionName: 777
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private xui As XUI
  
    Public const chaye_new As String  = "ca-app-pub-3940256099942544/1033173712"
    Public const tiaofu_new As String = "ca-app-pub-3940256099942544/6300978111"
    Public const jili_new As String   = "ca-app-pub-3940256099942544/5224354917"
  
    Public activity_return As Boolean = False
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    Dim bannerad As AdView
    Private mwAdInterstitial As InterstitialAd
    Private rewad As RewardedVideoAd
    Private Button2 As Button 'jump to activity2
    Private Button3 As Button 'rewad ad show
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")
  
    bannerad.Initialize2("BannerAd", tiaofu_new, bannerad.SIZE_BANNER)
    Dim ad_left1 As Int
    ad_left1 = (100%x-320dip)/2
    Dim ad_top1 As Int
    ad_top1 = 100%y - 50dip
    Activity.AddView(bannerad, ad_left1,ad_top1,320dip,50dip)
    BannerAdLoad
  
    rewad.Initialize("rewad")
    RewadLoadAd
    ModeRewadRequest
  
    mwAdInterstitial.Initialize("mwadi",chaye_new)
    mwAdInterstitialLoadAd
    ModeMwadiRequest
End Sub

Sub Activity_Resume
    If activity_return = True Then
        activity_return = False
        If mwAdInterstitial.Ready Then
            mwAdInterstitial.show
        End If
    End If
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    bannerad.Pause
End Sub


'close app
Sub Button1_Click
    xui.MsgboxAsync("Hello world!", "B4X")
    Dim jo As JavaObject
    jo.InitializeContext
    jo.RunMethod("finishAffinity",Null)
End Sub

Sub Button2_Click
    StartActivity(Activity2)
End Sub

Sub Button3_Click
    If rewad.Ready Then
        rewad.Show
    End If
End Sub

'------------------------------------------

Sub BannerAdLoad
    Dim builder As AdRequestBuilder
    builder.Initialize
  
    'Use RequestConfiguration.Builder().setTestDeviceIds(Arrays.asList("xxx") to get test ads on this device.
    '("D4AC977CA12D122C4563730CC762C302") '蓝叠模拟器的广告测试序列号
    '("D68B2332CAA15E64F14F13524AEE337A") '华为黑色手机的广告测试序列号
    '("92E503E8E51AC620FE34F44AB04F65E6") 华为金色手机的广告测试序列号
    '("E5069C6FE9A5AD36155002D5359C8186") REDMI9A
    builder.AddTestDevice("92E503E8E51AC620FE34F44AB04F65E6")
    builder.AddTestDevice("D68B2332CAA15E64F14F13524AEE337A")
    builder.AddTestDevice("E5069C6FE9A5AD36155002D5359C8186")
  
    bannerad.LoadAdWithBuilder(builder)
End Sub

Sub BannerAd_FailedToReceiveAd (ErrorCode As String)
    Log("BannerAd BannerAd_FailedToReceiveAd "&errstring(ErrorCode))
End Sub

Sub BannerAd_ReceiveAd
    Log("BannerAd ReceiveAd")
End Sub

Sub BannerAd_AdScreenDismissed
    Log("BannerAd AdScreenDismissed")
End Sub

Sub BannerAd_PresentScreen
    Log("BannerAd PresentScreen")
End Sub

'------------------------------------------

Sub RewadLoadAd
    Dim builder As AdRequestBuilder
    builder.Initialize
  
    'Use RequestConfiguration.Builder().setTestDeviceIds(Arrays.asList("xxx") to get test ads on this device.
    '("D4AC977CA12D122C4563730CC762C302") '蓝叠模拟器的广告测试序列号
    '("D68B2332CAA15E64F14F13524AEE337A") '华为黑色手机的广告测试序列号
    '("92E503E8E51AC620FE34F44AB04F65E6")华为金色手机的广告测试序列号
    '("E5069C6FE9A5AD36155002D5359C8186") 小米REDMI9A 广告测试序列号
    builder.AddTestDevice("92E503E8E51AC620FE34F44AB04F65E6")
    builder.AddTestDevice("D68B2332CAA15E64F14F13524AEE337A")
    builder.AddTestDevice("E5069C6FE9A5AD36155002D5359C8186")
  
    rewad.LoadAdWithBuilder(jili_new,builder)
    Log("Rewarded AD Load")
End Sub

'激励广告
Sub rewad_AdClosed
    Log("Rewarded Closed")
ModeRewadRequest
    Sleep(62000)
    RewadLoadAd
End Sub

Sub rewad_AdLeftApplication
    Log("rewad AdLeftApplication")
End Sub

Sub rewad_AdOpened
    Log("Rewarded Opened")
End Sub

Sub rewad_FailedToReceiveAd (ErrorCode As String)
    Log("Rewarded Failed: " & errstring(ErrorCode))
 ModeRewadRequest
    Sleep(62000)
    RewadLoadAd
End Sub

Sub rewad_ReceiveAd
    ModeRewadReady
    Log("rewad_ReceiveAd")
End Sub

Sub rewad_Rewarded (Item As Object)
    Log("rewad_Rewarded ")
    ToastMessageShow("rewad_Rewarded 1",False) '---显示提示
End Sub

Sub ModeRewadRequest
    Button3.Text = "Request rewad"
    Button3.TextColor = Colors.White  
End Sub

Sub ModeRewadReady
    Button3.Text = "rewad ready"
    Button3.TextColor = Colors.Yellow  
End Sub

'------------------------------------------

Sub mwAdInterstitialLoadAd
    Dim builder As AdRequestBuilder
    builder.Initialize
  
    'Use RequestConfiguration.Builder().setTestDeviceIds(Arrays.asList("xxx") to get test ads on this device.
    '("D4AC977CA12D122C4563730CC762C302") '蓝叠模拟器的广告测试序列号
    '("D68B2332CAA15E64F14F13524AEE337A") '华为黑色手机的广告测试序列号
    '("92E503E8E51AC620FE34F44AB04F65E6")华为金色手机的广告测试序列号
    '("E5069C6FE9A5AD36155002D5359C8186") 小米REDMI9A 广告测试序列号
    builder.AddTestDevice("92E503E8E51AC620FE34F44AB04F65E6")
    builder.AddTestDevice("D68B2332CAA15E64F14F13524AEE337A")
    builder.AddTestDevice("E5069C6FE9A5AD36155002D5359C8186")
  
    mwAdInterstitial.LoadAdWithBuilder(builder)
    Log("mwadi AD Load")
End Sub

Sub mwadi_AdClosed
    Log("mwadi AdClosed")
 ModeMwadiRequest
    Sleep(62000)
    mwAdInterstitialLoadAd
End Sub

Sub mwadi_AdLeftApplication
    Log("mwadi AdLeftApplication")
End Sub

Sub mwadi_AdOpened
    Log("mwadi AdOpened")
End Sub

Sub mwadi_FailedToReceiveAd(ErrorCode As String)
    Log("mwadi FailedToReceiveAd " & errstring( ErrorCode))
 ModeMwadiRequest
    Sleep(62000)
    mwAdInterstitialLoadAd
End Sub

Sub mwadi_ReceiveAd
    Log("mwadi ReceiveAd")
    ModeMwadiReady
End Sub

Sub ModeMwadiRequest
    Button2.TextColor = Colors.White  
End Sub

Sub ModeMwadiReady
    Button2.TextColor = Colors.Yellow  
End Sub

Sub errstring(ErrorCode As String) As String
    Select ErrorCode
        Case "0"
            Return "ERROR_CODE_INTERNAL_ERROR"
        Case "1"
            Return "ERROR_CODE_INVALID_REQUEST"
        Case "2"
            Return "ERROR_CODE_NETWORK_ERROR"
        Case "3"
            Return "ERROR_CODE_NO_FILL"
        Case Else
            Return ErrorCode
    End Select
End Sub
 

Attachments

  • PIC001.jpg
    PIC001.jpg
    95.9 KB · Views: 143
  • PIC002.jpg
    PIC002.jpg
    56.2 KB · Views: 139
  • PIC003.jpg
    PIC003.jpg
    45.3 KB · Views: 142
  • Starter.bas
    1.1 KB · Views: 140
  • Starter.bas
    1.1 KB · Views: 148
  • Activity2.bas
    900 bytes · Views: 131
Last edited:

kisoft

Well-Known Member
Licensed User
Longtime User
Hello, did you notice that the application size is increasing? Can you check it, just run and close the application a few times. Changes are coming soon, see this thread.
 
Upvote 0

Maodge

Member
Licensed User
Hello, did you notice that the application size is increasing? Can you check it, just run and close the application a few times. Changes are coming soon, see this thread.

hello,
Thank you for your advice.
To find out the cause of the problem, I test a project just with bannerAD.
if project has bannerad.pause and bannerad.RESUME code, app's power consumption will increased on redmi9A android10, even if switched to the background or manually close or removed from the recent list .
but if i remove this two line code, app's power consumption will pause as soon as app close or switched to the background on redmi9A android10.

A project just with bannerAD, and remove bannerad.pause and bannerad.RESUME code
I check this project app storage.
app size never change.but user data is increasing.
I just check 3 times. user data : 1.54MB --> 1.83MB -->1.88MB

A project just with bannerAD, and include bannerad.pause and bannerad.RESUME code
app size never change.
user data increasing : 0.98MB --> 1.37MB -->1.42MB

I list my code below. what's the problem with my code?

MAIN.B4A:
#Region  Project Attributes
    #ApplicationLabel: TEST ADS 02
    #VersionCode: 1
    #VersionName: 1
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private xui As XUI
   
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    Dim bannerad As AdView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")
    bannerad.Initialize2("BannerAd", "ca-app-pub-3940256099942544/6300978111", bannerad.SIZE_BANNER)
    Dim ad_left1 As Int
    ad_left1 = (100%x-320dip)/2
    Dim ad_top1 As Int
    ad_top1 = 100%y - 50dip
    '广告和乐曲信息等部件都在pnlMenu中
    Activity.AddView(bannerad, ad_left1,ad_top1,320dip,50dip)
    BannerAdLoad
End Sub

Sub Activity_Resume
    'bannerad.RESUME
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    'bannerad.pause '执行 功耗在android10 持续消耗.'没有该语句正常。

End Sub

Sub Button1_Click
    xui.MsgboxAsync("Hello world!", "B4X")
    Dim jo As JavaObject
    jo.InitializeContext
    jo.RunMethod("finishAffinity",Null)
End Sub

Sub BannerAdLoad
    Dim builder As AdRequestBuilder
    builder.Initialize
   
    'Use RequestConfiguration.Builder().setTestDeviceIds(Arrays.asList("xxx") to get test ads on this device.
    '("D4AC977CA12D122C4563730CC762C302") '蓝叠模拟器的广告测试序列号
    '("D68B2332CAA15E64F14F13524AEE337A") '华为黑色手机的广告测试序列号
    '("92E503E8E51AC620FE34F44AB04F65E6")华为金色手机的广告测试序列号
    '("E5069C6FE9A5AD36155002D5359C8186") 小米REDMI9A 广告测试序列号
    builder.AddTestDevice("92E503E8E51AC620FE34F44AB04F65E6")
    builder.AddTestDevice("D68B2332CAA15E64F14F13524AEE337A")
    builder.AddTestDevice("E5069C6FE9A5AD36155002D5359C8186")
   
    bannerad.LoadAdWithBuilder(builder)
End Sub


Sub BannerAd_FailedToReceiveAd (ErrorCode As String)
    Log("BannerAd BannerAd_FailedToReceiveAd "&errstring(ErrorCode))
End Sub

Sub BannerAd_ReceiveAd
    Log("BannerAd ReceiveAd " &DateTime.Now)
End Sub

Sub BannerAd_AdScreenDismissed
    Log("BannerAd AdScreenDismissed")
End Sub

Sub BannerAd_PresentScreen
    Log("BannerAd PresentScreen")
End Sub


Sub errstring(ErrorCode As String) As String
    Select ErrorCode
        Case "0"
            Return "ERROR_CODE_INTERNAL_ERROR"
        Case "1"
            Return "ERROR_CODE_INVALID_REQUEST"
        Case "2"
            Return "ERROR_CODE_NETWORK_ERROR"
        Case "3"
            Return "ERROR_CODE_NO_FILL"
        Case Else
            Return ErrorCode
    End Select
End Sub

starter:
#Region  Service Attributes
    #StartAtBoot: False
    #ExcludeFromLibrary: True
#End Region

Sub Process_Globals

End Sub

Sub Service_Create
    Dim mobileAds As MobileAds
    mobileAds.Initialize
End Sub

Sub Service_Start (StartingIntent As Intent)
    Service.StopAutomaticForeground
End Sub

Sub Service_TaskRemoved

End Sub

Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub

Sub Service_Destroy

End Sub
 
Upvote 0
Top