logo
down
shadow

Pause Android app until button press


Pause Android app until button press

By : user2948583
Date : November 14 2020, 04:51 PM
hop of those help? I have two methods: go() and stop(), and a for loop looping through these methods 3 times. go() activates automatically when the loop starts and stop() will only activate once a button is pressed 3 times: , You cannot pause main thread, the app freezes.
code :
private int loopCount = 0;
private int pressCount = 0;

public void button(View v) { /* Runs when button is clicked */
    if (loopCount < 4){
        pressCount++;

        if (pressCount == 3){
            pressCount = 0;
            loopCount++;
            stop();
        }
    }
}


Share : facebook icon twitter icon
how to pause program until a button press?

how to pause program until a button press?


By : Thomas L'Excellent
Date : March 29 2020, 07:55 AM
I wish this helpful for you Pausing Execution with Sleep, although I doubt that is the mechanism that you'll want to use. So, as others have suggested, I believe you'll need to implement wait-notify logic. Here's an extremely contrived example:
code :
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

@SuppressWarnings("serial")
public class PanelWithButton extends JPanel
{
    // Field members
    private AtomicBoolean paused;
    private JTextArea textArea;
    private JButton button;
    private Thread threadObject;

    /**
     * Constructor
     */
    public PanelWithButton()
    {
        paused = new AtomicBoolean(false);
        textArea = new JTextArea(5, 30);
        button = new JButton();

        initComponents();
    }

    /**
     * Initializes components
     */
    public void initComponents()
    {
        // Construct components
        textArea.setLineWrap(true);
        textArea.setWrapStyleWord(true);
        add( new JScrollPane(textArea));
        button.setPreferredSize(new Dimension(100, 100));
        button.setText("Pause");
        button.addActionListener(new ButtonListener());
        add(button);

        // Runnable that continually writes to text area
        Runnable runnable = new Runnable()
        {
            @Override
            public void run() 
            {
                while(true)
                {
                    for(int i = 0; i < Integer.MAX_VALUE; i++)
                    {
                        if(paused.get())
                        {
                            synchronized(threadObject)
                            {
                                // Pause
                                try 
                                {
                                    threadObject.wait();
                                } 
                                catch (InterruptedException e) 
                                {
                                }
                            }
                        }

                        // Write to text area
                        textArea.append(Integer.toString(i) + ", ");


                        // Sleep
                        try 
                        {
                            Thread.sleep(500);
                        } 
                        catch (InterruptedException e) 
                        {
                        }
                    }
                }
            }
        };
        threadObject = new Thread(runnable);
        threadObject.start();
    }

    @Override
    public Dimension getPreferredSize()
    {
        return new Dimension(400, 200);
    }

    /**
     * Button action listener
     * @author meherts
     *
     */
    class ButtonListener implements ActionListener
    {
        @Override
        public void actionPerformed(ActionEvent evt) 
        {
            if(!paused.get())
            {
                button.setText("Start");
                paused.set(true);
            }
            else
            {
                button.setText("Pause");
                paused.set(false);

                // Resume
                synchronized(threadObject)
                {
                    threadObject.notify();
                }
            }
        }
    }
}
 import javax.swing.JFrame;
    import javax.swing.SwingUtilities;


    public class MainClass 
    {
        /**
         * Main method of this application
         */
        public static void main(final String[] arg)
        {
            SwingUtilities.invokeLater(new Runnable()
            {
                public void run()
                {
                    JFrame frame = new JFrame();
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    frame.add(new PanelWithButton());
                    frame.pack();
                    frame.setVisible(true);
                    frame.setLocationRelativeTo(null);
                }
            });
        }
    }
pause functionality in Qt using QTimer on button press

pause functionality in Qt using QTimer on button press


By : Kristoffer Rønn-Ande
Date : March 29 2020, 07:55 AM
it fixes the issue That connection is in a bad place. You have it set up to connect each time you pause or resume the game. But if you connect multiple times, your slot will be called multiple tiles for each signal emission.
Make sure you only create the timer and connect to it once. I suggest moving the timer construction and signal connection into your GLWidget's constructor. Store a pointer to the timer as a member variable of your class so you can start and stop it in the class's member functions.
Pause execution until button press

Pause execution until button press


By : Gary Mulder
Date : March 29 2020, 07:55 AM
around this issue A simple way to do this is to process pending events inside the loop (so the UI remains responsive), and set/unset an internal flag to control starting and stopping of the loop.
The following demo script shows a basic implementation of this idea:
code :
import time
from PyQt4 import QtCore, QtGui

class Window(QtGui.QWidget):
    def __init__(self):
        QtGui.QWidget.__init__(self)
        layout = QtGui.QVBoxLayout(self)
        self.label = QtGui.QLabel(self)
        layout.addWidget(self.label)
        self.buttonStart = QtGui.QPushButton('Start', self)
        self.buttonStart.clicked.connect(self.handleStart)
        layout.addWidget(self.buttonStart)
        self.buttonStop = QtGui.QPushButton('Stop', self)
        self.buttonStop.clicked.connect(self.handleStop)
        layout.addWidget(self.buttonStop)
        self._running = False

    def handleStart(self):
        self.buttonStart.setDisabled(True)
        self._running = True
        while self._running:
            self.label.setText(str(time.clock()))
            QtGui.qApp.processEvents()
            time.sleep(0.05)
        self.buttonStart.setDisabled(False)

    def handleStop(self):
        self._running = False

if __name__ == '__main__':

    import sys
    app = QtGui.QApplication(sys.argv)
    window = Window()
    window.setGeometry(500, 300, 200, 100)
    window.show()
    sys.exit(app.exec_())
Need While Loop to pause to allow user to press a button in c#

Need While Loop to pause to allow user to press a button in c#


By : Su Youu
Date : March 29 2020, 07:55 AM
it helps some times I don't see a form anywhere, but expect that somewhere in that ChooseAttack(); call you have some code that looks like this:
MPRemoteCommandCenter : UI disappears after I press the pause button

MPRemoteCommandCenter : UI disappears after I press the pause button


By : dennajort
Date : March 29 2020, 07:55 AM
may help you . Just fixed this, for some reason, if you did not set any info to MPNowPlayingInfoCenter that's what happens, just happened to me, i added a random title and now the controls remain on the screen.
This behavior is weird but also understandable, if the remote controls don't have nothing to show, i could think that its ok to dismiss them.
Related Posts Related Posts :
  • The type org.openqa.selenium.firefox.FirefoxDriver is not accessible
  • Limitations (drawbacks) of java programming language?
  • Error: ')' expected Error: illegal start of expression
  • TableRowSorter use LookAndFeel of TableHeader, but own Comparator
  • Difference between @GeneratedValue and @GenericGenerator
  • Design Scenario: Smartphone class and will have derived classes like IPhone,AndroidPhone,WindowsMobilePhone can be even
  • Java date parsing without separators?
  • how to map an array of custom type from postgres to java using hibernate
  • Why hibernate always call "update" statement after using "select" statement in MySQL?
  • An interview topic: What can go wrong with this code?
  • How do I regex remove whitespace and newlines from a text, except for when they are in a json's string?
  • How to turn off Preferences > Compiles > User External Build?
  • how to convert arraylist to string array with all items in double quote
  • PMD+Maven+JAVA Error:: Can't find resource rulesets/comments.xml. Make sure the resource is a valid file or URL or is on
  • How to extend AbstractScheduledService.Scheduler
  • Primefaces tabview: set Active Index after some counting
  • Need help in Regex to exclude splitting string within "
  • Get header from HttpUrlConnection object
  • encoding xlsx as base64 and send it as an attachment
  • How to acess HttpServletRequest in Jaas login module in Tomcat
  • How to implement a basic pointer
  • Java Swing Exit Icon?
  • Why onNext has no effect
  • IntelliJ Idea 2018.2 no option for importing gradle project
  • Remove a negative element from an array w/o array.copy
  • Could this prevent overflow in Java?
  • In Java Swing, can I receive Caret events in real time?
  • I need help not using brute force when using JFrames and DrawWindows
  • How do I refactor ArrayList<MyClass> into MyClassLIst?
  • My program keeps saying that the method cannot be resolved
  • BubbleSort -my code returns random addresses
  • JavaFX components inside HTML?
  • Character in Java game not responding
  • Working around access denied in a FileWalking Tree in Java7
  • How to avoid if/else when using multple suppliers?
  • How to pass object from table cell editor to Table Model?
  • Paypal Sandbox payment state pending
  • sejda-console.bat passing parameters with spaces
  • Multiple Consumers Spring Kafka
  • Bitbucket pipeline: environmental variables in build.gradle file not recognized
  • Java static enum method to return a default enum value
  • What is the complexity of empty for loop?
  • Group randomly List of Lists as N subsets with K elements in each
  • How to set texture on a shape drawn by glDrawArrays()?
  • How to make a jlabel resizable according to the window
  • Java Mathematical Expression Syntax
  • assigning values to characters in java
  • Method overriding and Inheritance in java
  • given a set of lists/groups with a series of number, find matching numbers
  • Connection to HID USB device (keyboard and mouse) in android
  • Inject HttpServletRequest in CDI SessionScoped bean
  • Pool game in java - ball collision algorithm
  • Focus ScrollView to selected position programmatically - Android
  • Is it hibernate bug?
  • Glib memory allocation error
  • Android Proguard - step by step
  • Setting the pivot point of a JPanel to its center
  • java check time is greater time
  • how to save a screenshot (matlab)
  • Anti-aliasing filled shapes in libgdx
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org