【问题标题】:Foreground service has been killed automatically when MobileAds initializesMobileAds 初始化时,前台服务已自动终止
【发布时间】:2019-11-21 22:16:55
【问题描述】:

在我的主课中

@Override
protected void onCreate(Bundle savedInstanceState) {
{ 
 ..some code

 //first start foreground service 
 Intent serviceIntent = new Intent(this, ForegroundService.class);
 ContextCompat.startForegroundService(this, serviceIntent);
 //then i'm starting admob
 MobileAds.initialize(this,"ca-app-pub-3940256099942544/6300978111");
 mAddView = findViewById(R.id.adView);
 AdRequest adRequest = new AdRequest.Builder().build();
 mAddView.loadAd(adRequest);

..some code
}

如果没有 MobileAds.initialize(),当我关闭应用程序时,我的前台服务不会被终止。 使用 MobileAds.initialize() 我的前台服务被杀死了。

有人知道为什么吗?如何解决?

【问题讨论】:

    标签: android admob foreground-service googlemobileads


    【解决方案1】:

    你必须清除这条线

    MobileAds.initialize(this,"ca-app-pub-3940256099942544/6300978111");
    

    并将以下行添加到清单中

    <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>
    

    【讨论】:

      猜你喜欢
      • 2016-06-29
      • 1970-01-01
      • 2011-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多