how to make airpush smartwall appears after 3rd time on back button

i want to display the smartwallad after 3rd time the user exits the application how i can do that ? here is my code
thanks

public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
airpush.startSmartWallAd();
finish();

	}
	return super.onKeyDown(keyCode, event);
}

thanks,

Basically you’re going to want to store an Integer in storedPreferences that will track it. Every time the user presses back, accumulate it by 1. If it’s 3 or higher, show the appwall.

i thought there was easier method that doing this idea :stuck_out_tongue:
but thanks anyway :smiley:

i tried to do that but i can’t make it work right here is my code

int zft = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home_page);
zft =(PreferenceManager.getDefaultSharedPreferences(getBaseContext()).getInt(“counts”, 0));
}

@Override
public void onBackPressed() {

	checkforads();

	super.onBackPressed();
	
}

private void checkforads() {

	SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
	SharedPreferences.Editor edit = prefs.edit();

	
	if (zft <= 2) {
		edit.putInt("counts", zft ++);
		edit.commit();
		
	}else{
		edit.putInt("counts", 0);
		airpush.startSmartWallAd();
		Toast.makeText(this, "lol2", Toast.LENGTH_LONG).show();
	}
	
	
}

i don’t know where is the issue

I think were your mistake is:

edit.putInt(“counts”, zft ++);

the zft++ will increment zft AFTER it puts the value into the preferences. So you need to do it like this:

zft++;
edit.putInt(“counts”,zft);

thanks it works!!

@Override
public void onBackPressed() {
Airpush airpush=new Airpush(getApplicationContext(), null);
if (airpush!=null) {
airpush.startAppWall();

	     if(MoreAppManager.canShowMoreApp(this))
				MoreAppManager.show(this);
	 	else
			super.onBackPressed();
	}
}

This works perfectly for me. Except it works every exit on the app based on the interval of ad serving ofcourse. if(MoreAppManager.canShowMoreApp(this)), MoreAppManager.show(this); is not needed for thats just a widget i pop on 5th exit suggesting them to other apps of mine.

Let me know if you have issues.