googleads / googleads-mobile-android-examples

googleads-mobile-android
Apache License 2.0
1.68k stars 1.87k forks source link

Native Advanced Ad Android laggy in Recyclerview #211

Open sinhpn92 opened 4 years ago

sinhpn92 commented 4 years ago

I have tried to intergrate Native Advanced Ad into Recyclerview, but It is so laggy. I dont know why. I did fix site for media_view but it still lag.

Have any suggest to solve it?

Shvet commented 4 years ago

I have same problem, it take time to load data and make recyclerview slow to response on onscroll

sinhpn92 commented 4 years ago

I found that this issue by load ad. The UI has been blocking when loading ads :((. How can to fix it? 🍡

baderkhane commented 4 years ago

Apparently the issue coming from loadAd should be in separate thread

        new Timer().schedule(new TimerTask()
        {
            @Override
            public void run()
            {
                MainActivity.runOnUiThread(new Runnable()
                {
                    @Override
                    public void run()
                    {
                        AdRequest adRequest = new AdRequest.Builder()
                                .addTestDevice(AD_TEST_DEVICE)
                                .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
                                .build();

                        adView.loadAd(adRequest);
                    }
                });
            }
        }, 1000);
sinhpn92 commented 3 years ago

Apparently the issue coming from loadAd should be in separate thread

        new Timer().schedule(new TimerTask()
        {
            @Override
            public void run()
            {
                MainActivity.runOnUiThread(new Runnable()
                {
                    @Override
                    public void run()
                    {
                        AdRequest adRequest = new AdRequest.Builder()
                                .addTestDevice(AD_TEST_DEVICE)
                                .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
                                .build();

                        adView.loadAd(adRequest);
                    }
                });
            }
        }, 1000);

Why do we need delay 1 second to load ad?

sinhpn92 commented 3 years ago

I did try to load ad in the Couroutines with IO or Main. lifecycleScope.launch(Dispatchers.Main) {...} But It's still happening. Is there anyone has facing problem?

zeroarst commented 3 years ago

Having the same issue...

sinhpn92 commented 3 years ago

It's seem to be google cann't fix it. :(( This issue have been created long time ago.

zeroarst commented 3 years ago

It is actually not just on RecyclerView, it happens with all scrolls. I pull this repo https://github.com/googleads/googleads-mobile-android-examples/tree/master/kotlin/admob/NativeAdvancedExample and add a view with a height that higher than the screen, to make the screen scrollable. and I can see the lag. But the progress animation dose not lag at all. very weird.

sinhpn92 commented 3 years ago

Which's your test device? @zeroarst :(( I have tested on SamSung S10 Plus But It's still facing laggy. So bad

zeroarst commented 3 years ago

Mine is Samsung s7 edge

roma7481 commented 3 years ago

Any solution to this issue?

ArcherEmiya05 commented 3 years ago

I can confirm that this is not specific to RecyclerView as I noticed this as well with ScrollView. The UI freeze in a second when loading NativeAd com.google.android.gms.ads.nativead.NativeAdView. The lag starts when loading and ad.

ArcherEmiya05 commented 3 years ago

Apparently the issue coming from loadAd should be in separate thread

        new Timer().schedule(new TimerTask()
        {
            @Override
            public void run()
            {
                MainActivity.runOnUiThread(new Runnable()
                {
                    @Override
                    public void run()
                    {
                        AdRequest adRequest = new AdRequest.Builder()
                                .addTestDevice(AD_TEST_DEVICE)
                                .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
                                .build();

                        adView.loadAd(adRequest);
                    }
                });
            }
        }, 1000);

Need to correct you else you will keep believing in a wrong idea. That is not how you run heavy task on different thread. What you did here is add a delay then just literally run the heavy task in the main thread which is UI thus the lag is all still there, you just delay it occurrence . One of the basic way of running heavy task on a separate thread to not block the UI in order to avoid lag/freeze is with AsyncTask which is now deprecated. You can use Concurrent or Courutines when using Kotlin.

dexbyte commented 2 years ago

Facing the same issue here, is there any fix or a workaround at least?

Ynnck123 commented 2 years ago

I am also facing this issue, the loading of native ads seems to block the UI - running the ad loading in a coroutine doesn't change anything

abkoradiya commented 2 years ago

Same error. Need a solution for this.

7kashif commented 2 years ago

It's been years and still there is no fix.

Rdog69 commented 1 year ago

any solutions yet??

vamshikrishnag0 commented 1 month ago

Having the same issue. Any solution to this?