1

I want to show admob or appodeal ads in service and app wont be shown in the recent apps. I have tried many ways but didn't work.

I found this way but the app will come in recent apps!

‌‌‌‌‌‌‌‌‌‌‌‌ ‌‌‌

public class ServiceAd extends Service {

  private InterstitialAd mInterstitialAd;


  @Nullable
  @Override
  public IBinder onBind(Intent intent) {
    return null;
  }

  @Override
  public void onCreate() {
    super.onCreate();

    mInterstitialAd = new InterstitialAd(getApplicationContext());
    mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");

    mInterstitialAd.loadAd(new AdRequest.Builder().build());

    mInterstitialAd.setAdListener(new AdListener() {
      @Override
      public void onAdClosed() {
        // Load the next interstitial.
        mInterstitialAd.loadAd(new AdRequest.Builder().build());
        Log.d("tag", "on closed ad");
      }

    });

  }

  @Override
  public int onStartCommand(final Intent intent, int flags, int startId) {

    new Handler().postDelayed(new Runnable() {
      @Override
      public void run() {
        if (mInterstitialAd.isLoaded()) {
          mInterstitialAd.show();
        } else {
          Log.d("tag", "The interstitial wasn't loaded yet.");
        }
      }
    }, 5000);   // 5 mins
    return START_STICKY;
  }
}

0 Answers0