android – Showing Interstitial Ad After a Specific Number of Clicks/Touches On the Screen-ThrowExceptions

Exception or error:

I want to show an interstitial ad when a user clicks 5 times on the screen.
In everything of the screen when the user do 5 clicks/touches i want to show the ad.

How to solve:

Try below snippet and call your instantiate ad function in below snippet code:

import android.app.Activity;
import android.view.MotionEvent;
import android.widget.Toast;

public class aaa extends Activity {
    private int count = 0;
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        int eventaction = event.getAction();
        if (eventaction == MotionEvent.ACTION_UP) {
            count++;
            if (count == 5) {
                Toast.makeText(getApplicationContext(), "5 times", Toast.LENGTH_SHORT).show();
                count = 0;

                // Call your instantiate function and display ad here
            }
            return true;
        }
        return false;
    }
}

Instantiate ad Documentation here: Click Me

Hope this may helps you.

Leave a Reply

Your email address will not be published. Required fields are marked *