Issue with Animation not functioning properly when InterstitialAd is displayed

Ever since I was in grade 7, I have been passionate about building games and apps. Although I learned some XML back then, I lost my ambition over the years due to life's distractions. However, two weeks ago, I decided to teach myself Java and created a simple app called "Spin the Bottle." I've managed to work out most of the kinks, but now I'm facing a challenge that has me stuck.

The app runs perfectly fine without the counter that triggers an interstitial ad to pop up. But as soon as I add the code from "Button spin =(Button)" to "counter = 1; }else {...", the animation of the spinning bottle stops abruptly. I've spent the last two days scouring the web and experimenting with various solutions, but I haven't found the right fix yet. It's becoming quite frustrating, and any assistance would be immensely appreciated. Thank you in advance!

Answer №1

After some investigation, I discovered that there was a glitch in my animation script. I rewrote the code above and everything is now working fine. Perhaps this solution will be helpful for anyone looking to implement a click counter.

int counter = 0;

public void spin(View v) {


    if (counter == 4) {
        Log.i("log-", "INTERSTITIAL is loaded!");
        if (mInterstitialAd.isLoaded()) {
            mInterstitialAd.show();
        }
        counter = 1;
    }
    else {
        counter++;

        float newDirection = random.nextInt(3600);
        float pivoitX = imageView.getWidth() / 2;
        float pivoitY = imageView.getHeight() / 2;
        if (Math.abs(lastDirection - newDirection) < 360) {
            newDirection = lastDirection + newDirection + 360;
        }
        Animation rotate = new RotateAnimation(lastDirection, newDirection, pivoitX, pivoitY);

        rotate.setDuration(2000);
        rotate.setFillAfter(true);
        rotate.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                button.setEnabled(false);
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                button.setEnabled(true);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        lastDirection = newDirection;
        imageView.startAnimation(rotate);
    }


}
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating a div resizing function using only JavaScript is a fun and useful project to tackle

Seeking help to create a div resizer using only pure JavaScript as jQuery is restricted. The current functionality works, but breaks when the position of the slider-div is not set to absolute. Any solutions to fix this issue would be greatly appreciated. ...

Best practices for bulk inserting sequences in Node.js using MySQL

I have a dataset ready to be inserted into a MySQL database using nodejs. Here is the code I've written: con.connect(function (err) { myArray.forEach((el)=>{ con.query(1stQuery,1stValue,(error,result)=>{ //do something with ...

What are some strategies for avoiding data loss when rotating the screen on an Android app?

While using my android application, I encountered an issue when rotating the screen. The main functionality of my android application is to display a real-time ECG (electrocardiogram) signal by receiving it through an audio jack and storing it in a buffer ...

State in React Native causing asynchronous problems

I am working on developing a straightforward application that allows users to enter the name of a movie in a search bar. The app will then display a list of movies related to that specific title, sourced from an external public API. However, I have run int ...

Adjusting the drag mouse position in jqueryUI

I'm currently working on coding a Lockscreen design inspired by ios8. I want to create a draggable element that only moves along the x-axis. $( "#IDlsDragable" ).draggable({ axis: "x" }); .lockscreen { position:fixed; top:0px; left:0px; wid ...

The art of properly indenting coffee script code

I encountered an indentation error in these lines Are there any online validators that can assist me? showAliveTests : (pageIndex, statusFilter) -> data= pageIndex:pageIndex status:statusFilter $.ajax u ...

Include an additional icon without replacing the existing one on the mouse cursor

I am looking for a way to enhance the user experience by adding an icon that appears when hovering over an HTML element, serving as a subtle hint that the user can right-click. Instead of replacing the default cursor, which varies across platforms and doe ...

Looking for assistance in setting up a jar file on Amazon Web Services?

I'm feeling a bit lost and not sure which method to use for running a jar file. Specifically, I want to run the one found at https://github.com/Manevolent/EggCrack. Currently, I am connected to an ec2 instance using ssh, but I'm unsure of what st ...

Encountered an error with the POST request - TypeError: Unable to access the 'name' property as it is undefined

I'm currently facing some issues with using nodemailer to send emails. I believe I have everything set up correctly. I came across some posts mentioning deprecated code with the body parser, and I attempted their solutions...I think I've implemen ...

Enhancing server error troubleshooting with Next.js: improved stack trace visibility?

When a server error happens on Next.js, the call stack only provides information about the specific component where the error is located without offering any further guidance. For instance, in /pages/index.js, I have a component named Test. Within this co ...

How can I assign a distinct background color to individual sections in Chart.js?

Wanting to Customize Grid Background Colors in Line Chart using react-chartjs-2 I am looking to have different background colors for each grid in my Line chart. Is this functionality possible with the react-chartjs-2 library? This is the desired appearan ...

The GIPHY API object returns no results

Utilizing Angular 2 to fetch data from the GIPHY API. export class ListaGifsComponent { gifs : Object[] = []; urlBase = "http://api.giphy.com/v1/gifs/search?q="; termoPesquisado = "ryan+gosling"; key = "O8RhkTXfiSPmSCHosPAnhO70pdnHUiWn"; ...

We apologize, but the module you are looking for cannot be found: Unable to locate 'fs'

Trying to create a new MDX blog website using Next.js 13 with the latest app router, but encountering an error message saying "Module not found: Can't resolve 'fs'". It was working fine in Next.js 12 and pages directory, but not in the lates ...

Save an array of messages by making separate API calls for each one

I have a function that makes an API call to retrieve a list of message IDs. Here is the code: function getMessageList(auth) { api.users.messages.list({ auth: auth, userId: 'me', }, function(err, response) { if (er ...

Guide on Embedding a JavaScript Encapsulation Function within a Directive

I have encountered a situation where implementing an encapsulating function breaks my directive. Strangely, without the encapsulation, everything works fine. Has anyone else faced this issue before or can shed some light on why it might be causing the dire ...

Is there a way to showcase the data of each table row within the tr tag in an Angular 8 application?

I have been developing an application using Angular 8. The employee-list component is responsible for presenting data in a table format. Within the employee-list.component.ts file, I have defined: import { Component } from '@angular/core'; impo ...

Querying Mysql Data using Select Statement in Node.js

Hey there, I want to create an SQL clause using the following function function selectFrom(reqContents, callback) { connection.query('SELECT ?? FROM ?? WHERE ?', [ reqContents.attribute, reqContents.table, reqContents.GET ], function(err ...

Guide to extracting a targeted value from a collection of JSON Objects in a NodeJS environment

I've been attempting to use the code below to extract the executionArn, but I'm encountering the following error Error [SyntaxError]: Unexpected token o in JSON at position 1 at JSON.parse (<anonymous>) Is there a way to retrieve the e ...

Tips for sending a localstorage value as a parameter in an axios request

Currently, in my React app, I am using Express to handle all of my database queries. One thing I am attempting to achieve is passing the user id stored in local storage into a post request. This is necessary for my application since it revolves around use ...

Ajax: If a GET request is made, the page will automatically refresh

EcmaScript 6, jQuery 3.1.0 Fiddle: https://jsfiddle.net/Kifsif/k6gw1gnw/10/ Heroku: A plus sign can be found on the page which is supposed to add a form just above it when clicked. The issue arises when adding a form via AJAX as it ends up being displa ...