java – Is it allowed to load an old ad request when going back to previous activity?-ThrowExceptions

Exception or error:

I’m using the library Umano SlidingUpPanel which expands when i press a button and my MainActivity is then overlapped by this panel.

Now i read somewhere that Admob Ads should not be requested/active when they are not visible to the user and the problem is that i have a Native Ad on my MainActivity which then would not be visible if the user stays on the expanded state.

So should i just destroy the Native Ad when the panel is expanded and then reload the ad again when the panel is collapsed with the old ad request or request a new one?

This is the code i use to also load an Ad on the slide panel.

    public void onPanelStateChanged(View panel, SlidingUpPanelLayout.PanelState previousState, SlidingUpPanelLayout.PanelState newState) {
        if (newState.equals(SlidingUpPanelLayout.PanelState.EXPANDED)){
            if (nativeAd != null){
                Log.d(TAG, "SlidingUpPanel EXPANDED: nativeAd destroy!");
            if (nativeAd2 == null){
                Log.d(TAG, "SlidingUpPanel EXPANDED: refreshAd()");
            }else {
                Log.d(TAG, "SlidingUpPanel EXPANDED: nativeAd != null : adLoaderSong load ad!");
        if (newState.equals(SlidingUpPanelLayout.PanelState.COLLAPSED) || newState.equals(SlidingUpPanelLayout.PanelState.HIDDEN)
        && previousState.equals(SlidingUpPanelLayout.PanelState.EXPANDED)) {
            if (nativeAd2 != null) {
                Log.d(TAG, "SlidingUpPanel COLLAPSED or HIDDEN: nativeAd2 destroy!");
            Log.d(TAG,"SlidingUpPanel ad: " +adRequest.toString());


I stored the Ad Request in a global variable and i reloaded the ad with the same ad request, but it shows a new ad for some reason?

But Log.d(TAG,"SlidingUpPanel ad: " +adRequest.toString()); shows the same string in logcat.

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *