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:
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
Last edited: