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 are the notifications available in android?
What is Android?
FCM Not Receiving Notifications in Android - RRutors
How to start a new activity on button click
How to Exit android app on back pressed?
How to avoid multiple button click at same time in android?
How to get an image resource by it's name in android?
How to validate email address in Android with Kotlin?
Fix Behavior Subclass BottomSheetBehavior Exception - RRutors
What is Application?
Explain Fragment Life Cycle
What is ANR? How to avoid and resolve it?
How to get a contact image using a phone number in android?
How to install/ uninstall apk by command line ADB
Fix Duplicate Files in APK Build.gradle Issue - RRutors
What happens next when the device switches between portrait and landscape?
How to Generate signed apk with android studio
What is Context?
How can i comment inside xml file in android studio?
Fix Play Store Rejection Due to SMS Permission - RRutors
What is "shared preferences" in Android ?
What are Android Versions available?
How to check Android version?
Invoke-customs are only supported starting with android 0 --min-api 26
ERR_ACCESS_DENIED in Android Webview with sdk 30
How do I generate random numbers in Dart?
Open PDF in Google Drive with Intent in Android - RRutors
What is ANR in android?
Symmetric vs Asymmetric Encryption in Android Server - RRutors
What is Android Fragments?
How to Get bitmap from drawable: Android
What is the Different Between val and var in Kotlin?
How to save activity State in Android?
Hide/Disable soft keyboard on Activity launch: Android
Fix Error: Use JsonReader.setLenient(true) for Malformed JSON
What is the difference between match_parent and fill_parent?
How to Use Deprecated Handler() in Android - RRutors Guide
How To Set Text Color Programmatically Android TextView?
Decompile APK Files: How to Get Source Code - RRutors Guide
How to get screen size (width,height) in Android?