SQL Server and Async class error android.os.NetworkOnMainThreadException

jm81lzqq  于 2023-03-28  发布在  SQL Server
关注(0)|答案(1)|浏览(137)

I'm developing an app with Android Studio, java. I perform some operations that require an Async class. After I started using such classes, other activities are no longer able to connect to Sql Server, returning the error message: android.os.NetworkOnMainThreadException.

The Activity that is showing this error does not make any calls or uses Async routines. But after I implemented some Async class in my project, I can no longer minimally open a database in SQL Server.

Does anyone know what the problem is or can explain to me what I'm doing wrong.

Async classes work perfectly fine without any issues.

6bc51xsx

6bc51xsx1#

Request Data either local or network , It suppose to be request from Background Thread.
android.os.NetworkOnMainThreadException

Runnable runnable = new Runnable() {
            @Override
            public void run() {
                // request 
                
                runOnUiThread(() -> { // main thread
                    // update ui
                });
            }
        };
        runnable.run();

相关问题