I have created four buttons with LinearLayout , my user must select one, when they are not selected they have a gray background and when you click on one your background changes to red and the one selected previously passes to gray.
Everything works fine, but after adding the advertising intersitial, my buttons only change color once, then they do not change the background, but the value is still working.
If I avoid loading the intersitial, everything will work normally again.
I am loading the intersitial at the start of my activity
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_calculadora_requerimientos)
val vibratorService = getSystemService(Context.VIBRATOR_SERVICE) as
Vibrator
val cfg = Config(baseContext)
mInterstitialAd = InterstitialAd(this)
mInterstitialAd.adUnitId = getString(R.string.admob_intersitial)
mInterstitialAd.loadAd(AdRequest.Builder().build())
Then, in another button that makes a change of intent sample my intersitial
if (mInterstitialAd.isLoaded) {
mInterstitialAd.show()
} else {
startActivity(intent)
}
mInterstitialAd.adListener = object: AdListener() {
override fun onAdLoaded() {
}
override fun onAdFailedToLoad(errorCode: Int) {
startActivity(intent)
}
override fun onAdClosed() {
startActivity(intent)
}
}
How I'm changing the background; After the call of other functions to check and modify the previous selection to avoid changing the background of the four buttons and only change one in order to improve performance, the change of the background is summarized in this:
if ( sedentaria.background.constantState == ContextCompat.getDrawable(ctx,R.drawable.bg_rectangle_no_selected)!!.constantState)
sedentaria.background = ResourcesCompat.getDrawable(resources, R.drawable.bg_rectangle_selected, null)
Why is the intersitial affecting my background change once it has been loaded?
I thought maybe the background was loading, only that it was falling under a layer and that's why the color was not appreciated, but I tried to add:
.bringToFront()
and the result has not been as expected.