Question: My application makes a call to the server which may take a few seconds. The user can minimize the App before receiving the response from the server.

So what I am trying to do is that if the App is minimized when it receives the response from the server, it will go to PIP mode.

When I try to enter Pip mode with the application minimized I get this error:

```
java.lang.IllegalStateException: Activity must be resumed to enter picture-in-picture

```

The error occurs when this line is executed:

```
enterPictureInPictureMode();

```

Thanks.

Answer: 
Simple, stop using persistent connections and restart the server.
Although it may see advantageous to increase `max_connections`, it will only make things worse. It sounds like you have lots of connections stumbling over each other -- none finishing.

Look at `SHOW PROCESSLIST`. One of the non-Sleeping ones with the largest "Time" (other than 'system' processes) *may* be the main offender.

If the Processlist shows more than, say, 30 connections that are non "Sleep", then lower `max_connections` and the timeouts. These will help unclog the system, but won't get to the root of the problem.

The "cause" is often one or a few long-running queries that block other connections. Let's try to find the offending query by using the slowlog: <http://mysql.rjweb.org/doc.php/mysql_analysis#slow_queries_and_slowlog>