2
I want to show my ad when the user presses to "return" where I should release this code: Adbuddiz.showAd(Activity);
2
I want to show my ad when the user presses to "return" where I should release this code: Adbuddiz.showAd(Activity);
2
To achieve the solution you must overwrite the method onBackPressed of Activity.
A solution would be:
public class SuaActivity extends Activity {
// Demais codigo de sua Activity...
@Override
public void onBackPressed() {
// Usuario apertou o botão voltar.
// Essa chamada é opcional, mas é uma boa prática
// deixar o comportamento padrão ocorrer
super.onBackPressed();
// Mostra seu Ads
AdBuddiz.showAd(this);
}
}
In the case of AdBuddiz, you need to register a AdBuddizDelegate to listen for events that occur with the Ads.
To complement the desired behavior, we will use some events to continue the "back" process. We will use the didFailToShowAd, didClick and didHideAd to effectively return1.
1I’m guessing you still don’t use the AdBuddizDelegate, and that only the SuaActivity calls the Ads. Otherwise it is necessary to adapt the code to handle multiple uses, since the AdBuddiz only allows 1 Adbuddizdelegate throughout your app
Applying in your Activity would be:
public class SuaActivity extends Activity implements AdBuddizDelegate {
// Flag para indicar se o usuário pode voltar (o Ads ja foi exibido ou falhou).
boolean mAdShownOrFailed = false;
// Flag para indicar que o usuário ja apertou o botao de voltar
boolean mBackPressed = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
// Restante codigo do seu onCreate
// Registramos o AdBuddizDelegate.
AdBuddiz.setDelegate(this);
}
// Restante do codigo de sua Activity...
@Override
public void onBackPressed() {
// Usuario apertou o botão voltar.
// A chamada ao super.onBackPressed() é opcional, mas é uma boa prática
// deixar o comportamento padrão ocorrer
// Como o Ads ja foi mostrado ou nao pode ser carregado,
// podemos permitir o usuario voltar
if(mAdShownOrFailed) {
super.onBackPressed();
return;
}
mBackPressed = true;
// Mostra seu Ads
AdBuddiz.showAd(this);
}
@Override
public void didCacheAd() {
// Ad foi colocado no cache, nao precisamos fazer nada
}
@Override
public void didShowAd() {
// O Ads foi mostrado, podemos permitir que ele aperte o
// botao de voltar novamente para sair.
mAdShownOrFailed = mBackPressed && true;
}
@Override
public void didFailToShowAd(AdBuddizError error) {
// O Ads falhou ao carregar, o usuario pode sair assim mesmo
mAdShownOrFailed = mBackPressed && true;
// Voce pode fechar a Activity caso queira, chamando onBackPressed()
//onBackPressed();
}
@Override
public void didClick() {
// Usuario clicou, podemos fechar a Activity
mAdShownOrFailed = mBackPressed && true;
onBackPressed();
}
@Override
public void didHideAd() {
// Usuario fechou o Ads, podemos fechar a Activity
mAdShownOrFailed = mBackPressed && true;
onBackPressed();
}
}
Displays ads when "back" but continues with open app(google policy), only after the ads are closed that the app disappears.
Okay, I’ll update, just a minute to see the documentation.
Browser other questions tagged android
You are not signed in. Login or sign up in order to post.
Which library of
Adsthis using?Admob`?– Wakim
I’m using the Adbuddiz
– JBarbosa