1

Mopub recommends using Singleton approach to displaying banners so the same ad view can be reused in different screens. See here for article.

Unfortunately, they have no examples or any sample code. Any suggestions on how to implement this on Android?

Currently, every activity in my app has this view in layout xml

<com.mopub.mobileads.MoPubView
   android:id="@+id/ad"
   android:layout_width="fill_parent"
   android:layout_height="@dimen/mopubHeight"
   android:layout_alignParentBottom="true"
   android:layout_centerHorizontal="true"
   android:orientation="horizontal"
/>

Then in code, every activity loads ad into view.

_ad = (MoPubView) findViewById(R.id.ad);
_ad.setAdUnitId(getString(R.string.mopub_id));
_ad.loadAd();

How do I convert this to singleton approach? I want to do this without converting all the activities in my app into fragments and keeping the ad view fragment in place. This would require that I refactor the entire app and would take too much time. Are there any other ideas?

amit
  • 1,373
  • 2
  • 16
  • 29

0 Answers0