I had similar problem. Only now I discovered that the standard intellIj and Android Studio mode are debug mode.
I reviewed the threads of my application on release mode, and replaced the threads of type 1 for threads of type 2:
Threads Type 1:
class TimeCheckURL extends TimerTask
{
@RequiresApi(api = Build.VERSION_CODES.M)
public void run()
{
new Thread(new Runnable() {
@Override
public void run() {
Data = null;
Data = new JsonTask().execute(urlBase);
threadEnd = true;
}
}).start();
}
}
Threads Type 2:
Thread threadReadHexBsvTx = new Thread(new Runnable() {
@Override
public void run() {
try {
Data = JsonTask(urlBase);
} catch (Exception e) {
e.printStackTrace();
}
}
});
private void renewThread()
{
threadReadHexBsvTx = new Thread(new Runnable() {
@Override
public void run() {
try {
Data = JsonTask(urlBase);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
To monitor if threads type 1 were still alive I used the following approach;
while (!threadEnd) {
//do something
}
It worked very well when I unknowingly developed under Build Variant Debug, however when I put it on playstore I discovered that there was a release variant, and that my application did not worked properly on release mode.
It happened because everytime the processes using threads type 1 were called for the second time, the thread did not updated "threadEnd" and it looped forever.
I discovered that I could monitor the state of thread type 2 using this aproach.
while (bsvTX.threadBroadCast.isAlive()) {
//do something
}
This solved the problem in my application. However, I could not use approach of thread type 2 on thread type 1.
It might sound very noob, but I also discovered that for threads type 2 to work the second time the processes called them, they had to be renewed, that is why I use the method renewThread().