Quantcast
Browsing all 191 articles
Browse latest View live

Answer by Richard Kamere for How do I fix...

I had a similar problem, I just used the following in oncreate method of your activity. //allow strict mode StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();...

View Article


Answer by Vipul Prajapati for How do I fix...

Do this in Background Thread using AsycTask Java class NetworkThread extends AsyncTask<String, Void, String> { protected Void doInBackground(String... arg0) { //Your implementation } protected...

View Article


Answer by Sazzad Hissain Khan for How do I fix...

Kotlin version internal class RetrieveFeedTask : AsyncTask<String, Void, RSSFeed>() { override fun doInBackground(vararg urls: String): RSSFeed? { try { // download // prepare RSSFeeds return...

View Article

Answer by Santanu Sur for How do I fix...

You can use Kotlin-coroutines class YoutActivity : AppCompatActivity, CoroutineScope { override fun onCreate(...) { launch { yourHeavyMethod() } } suspend fun yourHeavyMethod() { with(Dispatchers.IO){...

View Article

Answer by Devix for How do I fix 'android.os.NetworkOnMainThreadException'?

If you are working in kotlin and anko you can add doAsync { method() }

View Article


Answer by Ashok Kumar for How do I fix...

Different options: use normal java runnable thread to process network task and can use runOnUIThread() to update the UI intentservice/ async task can be used in case you want to update the UI after...

View Article

Answer by yoAlex5 for How do I fix 'android.os.NetworkOnMainThreadException'?

You are able to move a part of your code into another thread to offload the main thread and avoid getting ANR, NetworkOnMainThreadException, IllegalStateException(e.g. Cannot access database on the...

View Article

Answer by Elye for How do I fix 'android.os.NetworkOnMainThreadException'?

As of 2018, I would recommend to use RxJava in Kotlin for network fetching. A simple example is below. Single.fromCallable { // Your Network Fetching Code Network.fetchHttp(url) }...

View Article


Answer by KG6ZVP for How do I fix 'android.os.NetworkOnMainThreadException'?

There are many great answers already on this question, but a lot of great libraries have come out since those answers were posted. This is intended as a kind of newbie-guide. I will cover several use...

View Article


Answer by sharath kumar for How do I fix...

The main thread is the UI thread, and you cannot do an operation in the main thread which may block the user interaction. You can solve this in two ways: Force to do the task in the main thread like...

View Article

Answer by Rahul for How do I fix 'android.os.NetworkOnMainThreadException'?

Never do any long running work on UI thread, that long running work can be communication with server, read/write on file etc. These tasks should be on background thread, thats why Service, AsyncTask,...

View Article

Answer by J.D.1731 for How do I fix 'android.os.NetworkOnMainThreadException'?

You can either use KOTLIN and ANKO. Kotlin is new official language for Android more about it you can find here https://kotlinlang.org/docs/tutorials/kotlin-android.html Anko supported library for...

View Article

Answer by Shinoo Goyal for How do I fix...

RxAndroid is another better alternative to this problem and it saves us from hassles of creating threads and then posting results on Android UI thread. We just need to specify threads on which tasks...

View Article


Answer by Ravindra babu for How do I fix...

New Thread and AsyncTask solutions have been explained already. AsyncTask should ideally be used for short operations. Normal Thread is not preferable for Android. Have a look at alternate solution...

View Article

Answer by Hossain Ahamed for How do I fix...

You can not call network on the main thread or UI thread. On Android if you want to call network there are two options - Call asynctask, which will run one background thread to handle the network...

View Article


Answer by aks for How do I fix 'android.os.NetworkOnMainThreadException'?

As Android is working on a single thread, you should not do any network operation on the main thread. There are various ways to avoid this. Use the following way to perform a network operation...

View Article

Answer by Himanshu for How do I fix 'android.os.NetworkOnMainThreadException'?

You can also resolve this issue by using Strict Mode using the below code. It's also an alternative to resolving this issue. StrictMode.ThreadPolicy policy = new...

View Article


Answer by Mansuu.... for How do I fix 'android.os.NetworkOnMainThreadException'?

android.os.NetworkOnMainThreadException is thrown when network operations are performed on the main thread. You better do this in AsyncTask to remove this Exception. Write it this way: new...

View Article

Answer by Lovekush Vishwakarma for How do I fix...

How to fix android.os.NetworkOnMainThreadException What is NetworkOnMainThreadException: In Android all the UI operations we have to do on the UI thread (main thread). If we perform background...

View Article

Answer by Alex Shutov for How do I fix...

There is another very convenient way for tackling this issue - use rxJava's concurrency capabilities. You can execute any task in background and post results to main thread in a very convenient way, so...

View Article
Browsing all 191 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>