Application dies when a Thread enters suspend

1

I have an error when the miHilo.suspend(); , my application closes and shows me this error in the console.

  

11-14 10: 50: 38.088 2390-2536 / com.example.root.juegopuchale   E / AndroidRuntime: FATAL EXCEPTION: Thread-1788                                                                                 Process: com.example.root.juegopuchale, PID: 2390                                                                                 java.lang.UnsupportedOperationException                                                                                     at java.lang.Thread.suspend (Thread.java:1061)

    
asked by Montero 14.11.2016 в 18:15
source

1 answer

0

The suspend () method is obsolete, you can find references in the android documentation to this article: Because Thread .stop, Thread.suspend, Thread.resume and Runtime.runFinalizersOnExit are obsolete? (English) :

You can avoid using Thread.suspend() and Thread.resume() by:

public synchronized void mousePressed(MouseEvent e) {
    e.consume();

    threadSuspended = !threadSuspended;

    if (!threadSuspended)
        notify();
}

And adding the following code to the "execution loop":

            synchronized(this) {
                while (threadSuspended)
                    wait();
            }

You can not really restart a Thread (suspend> start), what you have to do is create a new instance.

Thread thread = new Thread();
thread.start();
    
answered by 14.11.2016 / 18:28
source