title: android java how to wait thread with running animation when onPause is called
body: <p>When calling thread.wait(), the thread makes the pause correctly, but after 10 seconds the application crashes in onPause state in this test application. Where is the mistake? I need a way to pause an animation, when the onPause() method is called. I already tried to synchronize the thread when calling run. Android studio is not printing the stack trace. Thank you for help!</p>
  <pre><code>public class MainActivity extends AppCompatActivity {
      ImageView imageView;
      ImageView imageView2;
  
      Thread thread;
  
      boolean isCreate;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          Log.i(&quot;OnCreate&quot;, &quot;onCreate&quot;);
          setContentView(R.layout.activity_main);
          imageView = findViewById(R.id.imageView);
          imageView2 = findViewById(R.id.imageView2);
  
          isCreate = true;
  
          imageView.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  Log.i(&quot;onCreate&quot;, &quot;onClick&quot;);
  
                  thread = new Thread(new Runnable() {
                      @Override
                      public void run() {
                          imageView.animate().scaleX(2.5f).scaleY(2.5f).setDuration(10000);
  
                      }
                  });
  
                  thread.run();
              }
          });
      }
  
      @Override
      protected void onStart() {...}
  
      @Override
      protected void onResume() {
          super.onResume();
          if(!isCreate) {
              synchronized (thread) {
                  thread.notify();
              }
          }
          else {
              isCreate = false;
          }
      }
  
      @Override
      protected void onPause() {
          super.onPause();
  
          synchronized (thread) {
              try {
                  thread.wait();
              } catch (InterruptedException ie) {
                  ie.printStackTrace();
              }
          }
      }
  
      @Override
      protected void onStop() {...}
  
      @Override
      protected void onDestroy() {...}
  }
  </code></pre>