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();
How to save activity State in Android?
How can i comment inside xml file in android studio?
What is Context?
ERR_ACCESS_DENIED in Android Webview with sdk 30
Open PDF in Google Drive with Intent in Android - RRutors
How to Exit android app on back pressed?
How to convert DP to Pixel and Pixel to Dp?
How to copy database from assets folder in android using kotlin
How to start a new activity on button click
Fix Behavior Subclass BottomSheetBehavior Exception - RRutors
Explain Fragment Life Cycle
What is Android?
How to get screen size (width,height) in Android?
How to get a contact image using a phone number in android?
Set Activity to Fullscreen Mode in Android - RRutors
Fix Error: Use JsonReader.setLenient(true) for Malformed JSON
How do I generate random numbers in Dart?
Extract Date and Time from Long Type Variable - RRutors
Symmetric vs Asymmetric Encryption in Android Server - RRutors
How do I check in SQLite whether a table exists?
INSTALL_FAILED_INVALID_APK: Split lib_slice_9_apk was defined multiple times. It is possible that th
Decompile APK Files: How to Get Source Code - RRutors Guide
How to get an image resource by it's name in android?
Add Jar/Library Files as Dependency in Android Studio
Invoke-customs are only supported starting with android 0 --min-api 26
What is ANR in android?
How to Get bitmap from drawable: Android
How to get complete address from latitude and longitude?
Permission denied for window type 2010 in Marshmallow device
What is the difference between match_parent and fill_parent?
How to Use Deprecated Handler() in Android - RRutors Guide
Check List for Generate Signed APK Android
Hide/Disable soft keyboard on Activity launch: Android
What is Intent? What is the difference between an implicit intent and an explicit intent?
What is the Different Between val and var in Kotlin?
What are the notifications available in android?
How to validate email address in Android with Kotlin?
How to avoid multiple button click at same time in android?
What happens next when the device switches between portrait and landscape?
Fix Duplicate Files in APK Build.gradle Issue - RRutors