Android Application Is Hanged And Showing Black Screen For 5-6 Seconds When Checking If A Server Port Is Open Or Not Using Threadpoolexecutor
Solution 1:
After some study, as far as I understood,
Android application is hanged and showing black screen for 5-6 seconds Because,
Future -
A Future represents the result of an asynchronous computation. Methods are provided to check if the computation is complete, to wait for its completion, and to retrieve the result of the computation.
So, it waits until operation is finished. You can get more info from here.
newFixedThreadPool -
At any point, at most nThreads threads will be active processing tasks. If additional tasks are submitted when all threads are active, they will wait in the queue until a thread is available.
Get more info from here.
The possible solution of your problem is to use ScheduledExecutorService.
Before that you can check Future is completed or not using
if (YOUR_FUTURE.isDone()){
result = (String) YOUR_FUTURE.get();
}
to avoid unwanted or extra loop.
Post a Comment for "Android Application Is Hanged And Showing Black Screen For 5-6 Seconds When Checking If A Server Port Is Open Or Not Using Threadpoolexecutor"