I would like to ask you the reason for my problem. I have many activities, 2 of them are: the main one and the activity of the game. I am using AdMob, it works well for me in other activities, the problem I have is that when I try to use it in a button inside a Dialog, in which I have a button to "restart" a game, it does not work for me. The idea is that when you click on it, it shows the ad; and after closing the ad, the game will restart normally. What is happening is that when you close the ad, send the main one.
//Aquí está el evento para cerrar el anuncio
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
requestNewInterstitial();
//Método para reiniciar el juego
reset_game();
}
});
requestNewInterstitial();
//Este evento es para el botón de reiniciar el juego
ImageButton resetGame =(ImageButton) dialog.findViewById(R.id.resetGame);
resetGame.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
} else {
reset_game();
dialog.dismiss();
}
}
});
dialog.show();
display_unlocked_card_alert();
Log.d( TAG,"unlocked_check value 2 = " + unlocked_check);
}
I know very well that in reset_game I do not invoke or anything of that to the Main, since there only I generate to the game, but anyway I leave it:
private void reset_game(){
HashMap data = MemoryGame.game_mode_for(mode, cards_no);
init_table((int) data.get("rows"), (int) data.get("cols"));
memory_game.generate((int) data.get("total_cards"));
//init_table(4, 5);
//memory_game.generate(4*5);
current_turn = 0;
select_1 = 0;
select_2 = 0;
c =0;
set_timer((int) data.get("time"));
update_game_state_view();
update_cards_state_view();
}
I really do not know why this happens, will it have something to do with being inside a Dialog?
EDITING
This problem I did not solve, I better changed the way to see the ads. Anyway I would like to know the error or the way to solve it, out of simple curiosity.
On request, I add the code of the Dialog:
//Es un dialogo personalizado
private void alert_win() {
dialog = new Dialog(GameScreen.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation;
dialog.setContentView(R.layout.winner_dialog);
dialog.setCanceledOnTouchOutside(false);
Typeface typeFace=Typeface.createFromAsset(getAssets(), "bellosmcp.ttf");
TextView moTextView = (TextView) dialog.findViewById(R.id.moTextView);
moTextView.setTypeface(typeFace);
moTextView.setText(String.valueOf(_turn_count));
TextView matchTextView = (TextView) dialog.findViewById(R.id.matchTextView);
matchTextView.setTypeface(typeFace);
movesTextView.setTypeface(typeFace);
matchTextView.setText(String.valueOf(_score));
TextView pairstextView =(TextView) dialog.findViewById(R.id.pairstextView);
pairstextView.setTypeface(typeFace);
pairstextView.setText(Integer.toString(c));
ImageView closeDialog = (ImageView) dialog.findViewById(R.id.close);
TextView highScoreTextView = (TextView) dialog.findViewById(R.id.high_Score);
highScoreTextView.setTypeface(typeFace);
highScoreTextView.setText(String.valueOf(user.high_score));
//Aquí está el botón para reiniciar
ImageButton resetGame =(ImageButton) dialog.findViewById(R.id.resetGame);
resetGame.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
//Aquí esta lo de las Ads
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
} else {
reset_game();
}
}
});
dialog.show();
The point is that if I showed the Ads, but at the time of closing it, if I reiciaba, the game but closed the activity redirecting to the Main of the game, that error I could not solve, better changed the way in which the ads will show.