"Native Ads Implementation in recyclerview android"

109 views
Skip to first unread message

Vicky's

unread,
Feb 26, 2024, 2:56:50 PM2/26/24
to Google Mobile Ads SDK Developers
I want to know is it right or not to use adLoader.loadAd(AdRequest.Builder().build()) code in recyclerview adapter.

Actually I'm showing users list from firestore with the help of Firestorerecyclerviewadapter. I'm showing ads after specific position in onbind I'm loading ads and showing so every time it creates new adview so it take some time to show ad and it also auto refresh on scrolling, there is no issue with the users but ads makes the recyclerview laggy and I can't scroll smoothly.

When I remove the ad code it works well no issues no lag. I want to resolve this issue that's why I'm asking the community for the help.

ياسين الشوبكي

unread,
Feb 26, 2024, 7:40:35 PM2/26/24
to Google Mobile Ads SDK Developers

اه

Mobile Ads SDK Forum Advisor

unread,
Feb 27, 2024, 2:26:11 AM2/27/24
to vs3...@gmail.com, google-adm...@googlegroups.com
Hi,

Thank you for contacting Mobile Ads SDK support team.

By reviewing your concern I understand that you are facing lags while loading and showing up ads in RecyclerViewAdapter class. loading Ads in Adapter class is not a best practice as this can lead to performance issues which are caused due to dynamic creation of AdViews and loading of ads when the list is being scrolled. This might lead to delay in rendering the views in the list. Hence it is always preferred to load ads in main activity which does not interfere with the ReCyclerView and showing the ads in ReCyclerView which are preloaded in the main activity is the best practice to follow.

you can refer the below banner Ad code snippet :(make some changes to the banner Ad Sample to convert it into Native Ad sample)

protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

 

    recyclerView = findViewById(R.id.recycler_view);

 

    // Use this setting to improve performance if you know that changes

    // in content do not change the layout size of the RecyclerView.

    recyclerView.setHasFixedSize(true);

 

    // Specify a linear layout manager.

    RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);

    recyclerView.setLayoutManager(layoutManager);

 

    // Update the RecyclerView item's list with menu items and banner ads.

    addMenuItemsFromJson();

    addBannerAds();

    loadBannerAds();

 

    // Specify an adapter.

    RecyclerView.Adapter<RecyclerView.ViewHolder> adapter = new RecyclerViewAdapter(this,

        recyclerViewItems);

    recyclerView.setAdapter(adapter);

}

 

private void addBannerAds() {

    // Loop through the items array and place a new banner ad in every ith position in

    // the items List.

    for (int i = 0; i <= recyclerViewItems.size(); i += ITEMS_PER_AD) {

        final AdView adView = new AdView(MainActivity.this);

        adView.setAdSize(AdSize.BANNER);

        adView.setAdUnitId(AD_UNIT_ID);

        recyclerViewItems.add(i, adView);

    }

}
or you can refer InlineAdaptiveBannerExample, which might be helpful for implementing Native Ads in ReCyclerView.


If you are facing any issue on implementing the NativeAds in RecyclerView Kindly share us your Sample project that's reproducing the issue Via reply to author option for further assistance from our team.

If the file(s) you are looking to share are less than 25mb in total you can attach them to this case on your next reply. If you are having trouble attaching your file to this case or if your file(s) are larger than 25mb, you can share your files with me by performing the following steps:

 

1. Navigate to

https://docs.google.com/forms/d/e/1FAIpQLSfkAiXMeYP-fw1W3Z-tT9uwmATEKO5X6S-th0gR2ezdKaaqfg/viewform?usp=pp_url&entry.400550049=Mobile+Ads+SDK&entry.460850823=5004Q00002rzSl9QAE&entry.80707362=00224884

2. Fill out all fields, and attach your file(s).

3. Please reply back on this thread when you have uploaded your file(s). Please do not share this link.

 
This message is in relation to case "ref:!00D1U01174p.!5004Q02rzSl9:ref"

Thanks,
 
Google Logo Mobile Ads SDK Team


 

Reply all
Reply to author
Forward
0 new messages