Hi
I notice that once I've called adView.loadAds(), my app starts consuming 30%-80% CPU, even when my app is idle.
This happens when I use Google Play Services 4.1.32 (as I'm trying to support API level 8 still).
Problem is still there even when I upgraded to 5.0.89.
I tried calling adView.pause(), adView.destroy(), but CPU usage is still high.
Anybody knows a workaround or fix? Thanks.
My code:
MyActivity.java
package com.example.kenneth.testapp1;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.FrameLayout;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
public class MyActivity extends ActionBarActivity {
private AdView adView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
// Load Ad
adView = new AdView(this);
adView.setAdUnitId("ca-xxxxxxxx");
adView.setAdSize(AdSize.SMART_BANNER);
adView.loadAd(new AdRequest.Builder().build());
FrameLayout fl = (FrameLayout)findViewById(R.id.frame);
fl.addView(adView);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
activity_my.xml
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MyActivity">
<TextView
android:text="@string/hello_world"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"/>
<FrameLayout
android:id="@+id/frame"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="bottom" android:background="@android:color/darker_gray"></FrameLayout>
</LinearLayout>
build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.example.kenneth.testapp1"
minSdkVersion 9
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:20.0.0'
// compile 'com.google.android.gms:play-services:4.1.32'
compile 'com.google.android.gms:play-services:5.0.89'
}
Monitored CPU use using
adb shell top -m 10