<activity android:name="com.google.android.gms.ads.AdActivity"Instead of
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
<activity android:name="com.google.android.gms.ads.AdActivity"
android:theme="@android:style/Theme.Translucent"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
mRetryButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // switchViews(); showInterstitial(); } });
Thanks for testing my code.
In my app, I'm not modifying views in the same place that I show the interstitial. For example: I update the views in onStart, and I'm showing the interstitial in onActivityResult (when certain activities are closed). I update my activity views in onStart because I need to update them every time the activity comes to foreground. And try to use onAdClose in this case will make code more complex.
I understand that doing something while showing an ad may slow down my app, but I don't understand why it leaves my activity unusable: my list is not updated anymore, some views disappear, and others are not in a correct position. And even if I retry to update my views later, they act in a weird behavior. After an interstitial is shown, the app doesn't work correctly until I restart it.
I'm using admob since 2011, and it never happened before, don't you think it's an admob bug?
class MySurfaceView extends SurfaceView implements Runnable {
Activity activity;
Context context;
Thread thread = null;
SurfaceHolder surfaceHolder;
volatile boolean running = false;
private Game game;
public MySurfaceView(Activity activity) {
super(activity);
surfaceHolder = getHolder();
this.activity= activity;
this.context= activity;
game= new Game ();
game.initialize(activity);
}
public void onResumeMySurfaceView () {
running = true;
thread = new Thread(this);
thread.start();
}
public void onPauseMySurfaceView () {
boolean retry = true;
running = false;
while (retry) {
try {
thread.join();
retry = false;
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
// @Override RUNNABLE
public void run() {
while (running) {
try { Thread.sleep(1); }
catch (Exception e) { }
if(surfaceHolder.getSurface().isValid()){
Canvas c = null;
try {
c = surfaceHolder.lockCanvas(null);
if (c!=null && game!=null) {
synchronized (surfaceHolder) {
game.run(c);
}
}
} finally {
// do this in a finally so that if an exception is thrown
// during the above, we don't leave the Surface in an
// inconsistent state
if (c != null) {
//surfaceHolder.unlockCanvasAndPost(c);
Surface surface = surfaceHolder.getSurface();
if (surface!=null && surface.isValid()) surfaceHolder.unlockCanvasAndPost(c);
}
}
}
}
}
}