This exception is occurs when we call the network calls in Main Thread. 1) Strict mode: 2) AsynkTask
Long Running process never run on Main Thread.
To solve this problem, having following ways
write this code in your onCreate method
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll()
.build();
StrictMode.setThreadPolicy(policy);
write your code inside doInBackground() method
private class DownloadFilesTask extends AsyncTask<Void, Void, Void> {
protected Long doInBackground(URL... urls) {
// write your code here
return ;
}
};
3) Using Thread
Thread thread = new Thread(new Runnable(){
@Override
public void run() {
try {
//Your code goes here
} catch (Exception e) {
e.printStackTrace();
}
}
});
thread.start();
What is Context?
How to get an image resource by it's name in android?
How to find Android Device UDID or unique ID?
Fix Behavior Subclass BottomSheetBehavior Exception - RRutors
How to install/ uninstall apk by command line ADB
Extract Date and Time from Long Type Variable - RRutors
Key Points to remember while develop the Android Application.
Decompile APK Files: How to Get Source Code - RRutors Guide
Symmetric vs Asymmetric Encryption in Android Server - RRutors
How to start a new activity on button click
How to convert milli seconds to hours, minutes and seconds in Android?
How to get screen size (width,height) in Android?
What is ANR in android?
ERR_ACCESS_DENIED in Android Webview with sdk 30
How to copy database from assets folder in android using kotlin
What is "shared preferences" in Android ?
What is Application?
How to reduce APK package size?
How to save activity State in Android?
What is the Different Between val and var in Kotlin?
How to stop EditText focus at Activity startup in Android?
How to get a contact image using a phone number in android?
Permission denied for window type 2010 in Marshmallow device
How to Generate signed apk with android studio
How to Get bitmap from drawable: Android
INSTALL_FAILED_INVALID_APK: Split lib_slice_9_apk was defined multiple times. It is possible that th
What are Android Versions available?
What is Android?
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
Fix Error: Use JsonReader.setLenient(true) for Malformed JSON
Hide/Disable soft keyboard on Activity launch: Android
Fix Play Store Rejection Due to SMS Permission - RRutors
How do I check in SQLite whether a table exists?
How do I generate random numbers in Dart?
Explain Fragment Life Cycle
Fix Android Emulator Kill Error When Running Your App
Open PDF in Google Drive with Intent in Android - RRutors
Check List for Generate Signed APK Android
What is NetworkOnMainThread Exception?
How to avoid multiple button click at same time in android?