android - How to throw NetworkOnMainThreadException? -


i creating classes not implement threading logic need used off main thread, want throw networkonmainthreadexception (or similar 1 db operations) in constructors. how do that? how android that, can find somewhere in source code?

you check current's thread looper. e.g.

if (looper.mylooper() == looper.getmainlooper()) {    throw new networkonmainthreadexception(); } 

i avoid anyway. if in document method/class clarify has executed on asynchronously


Comments