<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mohit Manuja on Medium]]></title>
        <description><![CDATA[Stories by Mohit Manuja on Medium]]></description>
        <link>https://medium.com/@mohitmanuja?source=rss-a232e39867c6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*STBWa5Bp5Bmb_8GnpaXuXg.jpeg</url>
            <title>Stories by Mohit Manuja on Medium</title>
            <link>https://medium.com/@mohitmanuja?source=rss-a232e39867c6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 19:43:33 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mohitmanuja/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Experimenting new Admob Open AD]]></title>
            <link>https://medium.com/@mohitmanuja/experimenting-new-admob-open-ad-613fe404e93f?source=rss-a232e39867c6------2</link>
            <guid isPermaLink="false">https://medium.com/p/613fe404e93f</guid>
            <category><![CDATA[admob-new-ad]]></category>
            <category><![CDATA[admob]]></category>
            <category><![CDATA[app-open-ads]]></category>
            <category><![CDATA[earn-money-online]]></category>
            <category><![CDATA[app-open-admob]]></category>
            <dc:creator><![CDATA[Mohit Manuja]]></dc:creator>
            <pubDate>Sun, 20 Sep 2020 10:02:34 GMT</pubDate>
            <atom:updated>2020-09-27T11:51:34.069Z</atom:updated>
            <content:encoded><![CDATA[<h3>App Open Ad (Admob Beta)- How to implement?</h3><p>Hey guys, If you are using Admob in your apps then you might know google AdMob has added a new AD type — Open Ad (it’s in beta as of now and may be limited for some developers). Let’s try this ad and see how it works.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tTipX7tPt-gj-wMUtVcsDQ.png" /><figcaption>App Open (Beta) by Admob</figcaption></figure><p><strong>What is App Open AD?</strong></p><p>This is a new AD type that we can show to users when he minimises our app and comes back. An ad format that appears when users open or switches back to your app. Ad overlays the loading screen.</p><p>Let’s start to implement this Ad.</p><p><strong>Step 1</strong></p><p>Add the following dependency or update the version if you are implementing it in your old project. it should be ≥19.4.0</p><pre>implementation &#39;com.google.android.gms:play-services-ads:19.4.0&#39;</pre><p><strong>Step 2</strong></p><p>Create MyApplication class and extends it to Application Class.</p><pre><strong>public class </strong>MyApplication <strong>extends </strong>Application {<br>    @Override<br>    <strong>public void </strong>onCreate() {<br>        <strong>super</strong>.onCreate();<br>        MobileAds.<em>initialize</em>(<br>                <strong>this</strong>,<br>                <strong>new </strong>OnInitializationCompleteListener() {<br>                    @Override<br>                    <strong>public void </strong>onInitializationComplete(InitializationStatus initializationStatus) {}<br>                });<br>    }<br>}</pre><p><strong>Step 3</strong></p><p>Pass this application class to your manifest and also add your AdMob ad id in metadata as following.</p><pre>&lt;application<br>    <strong>android:name=&quot;.MyApplication&quot;</strong><br>...&gt;</pre><pre>&lt;<strong>meta-data<br>    android:name=&quot;com.google.android.gms.ads.APPLICATION_ID&quot;<br>    android:value=&quot;ca-app-pub-3940256099942544~3347511713&quot;</strong>/&gt;</pre><pre>&lt;/application&gt;</pre><p>Now it’s time to check google Admob documentation.</p><p>After the above steps Create a utility class for managing the app open ad.</p><p><strong>Step 4</strong></p><pre><strong>package </strong>com.admob.example.open;<br><br><strong>import </strong>android.app.Activity;<br><strong>import </strong>android.app.Application;<br><strong>import </strong>android.os.Bundle;<br><strong>import </strong>android.util.Log;<br><br><strong>import </strong>androidx.annotation.NonNull;<br><strong>import </strong>androidx.annotation.Nullable;<br><strong>import </strong>androidx.lifecycle.LifecycleObserver;<br><strong>import </strong>androidx.lifecycle.OnLifecycleEvent;<br><strong>import </strong>androidx.lifecycle.ProcessLifecycleOwner;<br><br><strong>import </strong>com.google.android.gms.ads.AdError;<br><strong>import </strong>com.google.android.gms.ads.AdRequest;<br><strong>import </strong>com.google.android.gms.ads.FullScreenContentCallback;<br><strong>import </strong>com.google.android.gms.ads.LoadAdError;<br><strong>import </strong>com.google.android.gms.ads.appopen.AppOpenAd;<br><br><strong>import static </strong>androidx.lifecycle.Lifecycle.Event.<strong><em>ON_START</em></strong>;<br><br><em>/**<br> * Prefetches App Open Ads.<br> */<br></em><strong>public class </strong>AppOpenManager <strong>implements </strong>Application.ActivityLifecycleCallbacks, LifecycleObserver {<br>    <strong>private static final </strong>String <strong><em>LOG_TAG </em></strong>= <strong>&quot;AppOpenManager&quot;</strong>;<br>    <strong>private static final </strong>String <strong><em>AD_UNIT_ID </em></strong>= <strong>&quot;ca-app-pub-68959573532223023/3473201416&quot;</strong>;<br>    <strong>private </strong>AppOpenAd <strong>appOpenAd </strong>= <strong>null</strong>;<br><br>    <strong>private </strong>AppOpenAd.AppOpenAdLoadCallback <strong>loadCallback</strong>;<br>    <strong>private </strong>Activity <strong>currentActivity</strong>;<br>    <strong>private static boolean </strong><em>isShowingAd </em>= <strong>false</strong>;<br><br>    <strong>private final </strong>Application <strong>myApplication</strong>;<br><br>    <em>/**<br>     * Constructor<br>     */<br>    </em><strong>public </strong>AppOpenManager(Application myApplication) {<br>        <strong>this</strong>.<strong>myApplication </strong>= myApplication;<br>        <strong>this</strong>.<strong>myApplication</strong>.registerActivityLifecycleCallbacks(<strong>this</strong>);<br>        ProcessLifecycleOwner.get().getLifecycle().addObserver(<strong>this</strong>);<br><br>    }<br><br>    <em>/**<br>     * Request an ad<br>     */<br>    </em><strong>public void </strong>fetchAd() {<br>        <em>// Have unused ad, no need to fetch another.<br>        </em><strong>if </strong>(isAdAvailable()) {<br>            <strong>return</strong>;<br>        }<br><br>        <strong>loadCallback </strong>=<br>                <strong>new </strong>AppOpenAd.AppOpenAdLoadCallback() {<br>                    <em>/**<br>                     * Called when an app open ad has loaded.<br>                     *<br>                     * </em><strong><em>@param ad </em></strong><em>the loaded app open ad.<br>                     */<br>                    </em>@Override<br>                    <strong>public void </strong>onAppOpenAdLoaded(AppOpenAd ad) {<br>                        AppOpenManager.<strong>this</strong>.<strong>appOpenAd </strong>= ad;<br>                    }<br><br>                    <em>/**<br>                     * Called when an app open ad has failed to load.<br>                     *<br>                     * </em><strong><em>@param loadAdError </em></strong><em>the error.<br>                     */<br>                    </em>@Override<br>                    <strong>public void </strong>onAppOpenAdFailedToLoad(LoadAdError loadAdError) {<br>                        <em>// Handle the error.<br>                        </em>Log.<em>d</em>(<strong><em>LOG_TAG</em></strong>,<strong>&quot;error in loading&quot;</strong>);<br>                    }<br><br>                };<br>        AdRequest request = getAdRequest();<br>        AppOpenAd.<em>load</em>(<br>                <strong>myApplication</strong>, <strong><em>AD_UNIT_ID</em></strong>, request,<br>                AppOpenAd.<strong><em>APP_OPEN_AD_ORIENTATION_PORTRAIT</em></strong>, <strong>loadCallback</strong>);<br>    }<br><br>    <em>/**<br>     * Shows the ad if one isn&#39;t already showing.<br>     */<br>    </em><strong>public void </strong>showAdIfAvailable() {<br>        <em>// Only show ad if there is not already an app open ad currently showing<br>        // and an ad is available.<br>        </em><strong>if </strong>(!<em>isShowingAd </em>&amp;&amp; isAdAvailable()) {<br>            Log.<em>d</em>(<strong><em>LOG_TAG</em></strong>, <strong>&quot;Will show ad.&quot;</strong>);<br><br>            FullScreenContentCallback fullScreenContentCallback =<br>                    <strong>new </strong>FullScreenContentCallback() {<br>                        @Override<br>                        <strong>public void </strong>onAdDismissedFullScreenContent() {<br>                            <em>// Set the reference to null so isAdAvailable() returns false.<br>                            </em>AppOpenManager.<strong>this</strong>.<strong>appOpenAd </strong>= <strong>null</strong>;<br>                            <em>isShowingAd </em>= <strong>false</strong>;<br>                            fetchAd();<br>                        }<br><br>                        @Override<br>                        <strong>public void </strong>onAdFailedToShowFullScreenContent(AdError adError) {<br>                        }<br><br>                        @Override<br>                        <strong>public void </strong>onAdShowedFullScreenContent() {<br>                            <em>isShowingAd </em>= <strong>true</strong>;<br>                        }<br>                    };<br><br>            <strong>appOpenAd</strong>.show(<strong>currentActivity</strong>, fullScreenContentCallback);<br><br>        } <strong>else </strong>{<br>            Log.<em>d</em>(<strong><em>LOG_TAG</em></strong>, <strong>&quot;Can not show ad.&quot;</strong>);<br>            fetchAd();<br>        }<br>    }<br><br>    <em>/**<br>     * Creates and returns ad request.<br>     */<br>    </em><strong>private </strong>AdRequest getAdRequest() {<br>        <strong>return new </strong>AdRequest.Builder().build();<br>    }<br><br>    <em>/**<br>     * Utility method that checks if ad exists and can be shown.<br>     */<br>    </em><strong>public boolean </strong>isAdAvailable() {<br>        <strong>return appOpenAd </strong>!= <strong>null</strong>;<br>    }<br><br>    @Override<br>    <strong>public void </strong>onActivityCreated(@NonNull Activity activity, @Nullable Bundle bundle) {<br><br>    }<br><br>    @Override<br>    <strong>public void </strong>onActivityStarted(@NonNull Activity activity) {<br>        <strong>currentActivity </strong>= activity;<br><br>    }<br><br>    @Override<br>    <strong>public void </strong>onActivityResumed(@NonNull Activity activity) {<br>        <strong>currentActivity </strong>= activity;<br><br>    }<br><br>    @Override<br>    <strong>public void </strong>onActivityPaused(@NonNull Activity activity) {<br><br>    }<br><br>    @Override<br>    <strong>public void </strong>onActivityStopped(@NonNull Activity activity) {<br><br>    }<br><br>    @Override<br>    <strong>public void </strong>onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle bundle) {<br><br>    }<br><br>    @Override<br>    <strong>public void </strong>onActivityDestroyed(@NonNull Activity activity) {<br>        <strong>currentActivity </strong>= <strong>null</strong>;<br><br>    }<br>    <em>/** LifecycleObserver methods */<br>    </em>@OnLifecycleEvent(<strong><em>ON_START</em></strong>)<br>    <strong>public void </strong>onStart() {<br>        showAdIfAvailable();<br>        Log.<em>d</em>(<strong><em>LOG_TAG</em></strong>, <strong>&quot;onStart&quot;</strong>);<br>    }<br>}</pre><p>In the above code replace <strong><em>AD_UNIT_ID </em></strong>with your Admob AD id.</p><p><strong>Step 5</strong></p><p>Now in the above class, you will get an error ProcessLifecycleOwner not able to resolve. To solve that we need to implement the following dependencies</p><pre><strong>def </strong>lifecycle_version = <strong>&quot;2.0.0&quot;<br></strong>implementation <strong>&quot;androidx.lifecycle:lifecycle-extensions:</strong>$lifecycle_version<strong>&quot;<br></strong>implementation <strong>&quot;androidx.lifecycle:lifecycle-runtime:</strong>$lifecycle_version<strong>&quot;<br></strong>annotationProcessor <strong>&quot;androidx.lifecycle:lifecycle-compiler:</strong>$lifecycle_version<strong>&quot;</strong></pre><p><strong>Step 6</strong></p><p>Now we need to listen for activity lifecycle events to register that we have to add the following code and after that our MyApplication class will look like this.</p><pre><strong>public class </strong>Application <strong>extends </strong>MultiDexApplication {<br>    AppOpenManager <strong>appOpenManager</strong>;<br>    @Override<br>    <strong>public void </strong>onCreate() {<br>        <strong>super</strong>.onCreate();<br>        MobileAds.<em>initialize</em>(<br>                <strong>this</strong>,<br>                <strong>new </strong>OnInitializationCompleteListener() {<br>                    @Override<br>                    <strong>public void </strong>onInitializationComplete(InitializationStatus initializationStatus) {<br>                    }<br>                });<br><br>        <strong>appOpenManager </strong>= <strong>new </strong>AppOpenManager(<strong>this</strong>);<br><br>    }<br>}</pre><p><strong>All done.</strong></p><p>Now we will run our app and see how it looks. To test it minimize your app and open it again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZM0WDinWtIoX144jEO-K5A.png" /><figcaption>App Open Ad</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gflGzqIz97gnM-rYwovwQg.png" /></figure><p>If you are getting any error try to replace your AD id with test ad id. Because AdMob takes some time to serve ads on new ads ids.</p><p>Hope you enjoyed the blog.</p><p>Here is the sample source code for the implementation of Admob Open Ad.</p><p><a href="https://github.com/mohitmanuja/App-Open-Ads-Example-Admob">https://github.com/mohitmanuja/App-Open-Ads-Example-Admob</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=613fe404e93f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>