Problem changing background of a LinearLayout after adding an Android Studio intersitial

0

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.

    
asked by César Alejandro M 18.11.2018 в 18:01
source

2 answers

0

To debug views loaded at runtime, use this Android Studio tool. In the IDE bar while you have the app launched from the ide, hit tools > Layout Inserto or double shift and type Layout Inspector . There you can see the layout that you want to debug your mobile or emulator.

    
answered by 18.11.2018 в 18:10
0

I have been able to identify the problem, I had MobileAds.initialize () in a main activity (activity parent where the error occurred with the layout) and prior to that I had a splashscreen. For some reason, even though MobileAds.initialize () was loading an activity before, it was conflicting. I've loaded it into the splash (the first activity that launches my APP) and everything worked great.

    
answered by 21.11.2018 в 14:33