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();
Open PDF in Google Drive with Intent in Android - RRutors
Fix Duplicate Files in APK Build.gradle Issue - RRutors
Check List for Generate Signed APK Android
What happens next when the device switches between portrait and landscape?
Invoke-customs are only supported starting with android 0 --min-api 26
Fix Behavior Subclass BottomSheetBehavior Exception - RRutors
Fix Play Store Rejection Due to SMS Permission - RRutors
FCM Not Receiving Notifications in Android - RRutors
What is Android Fragments?
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
Symmetric vs Asymmetric Encryption in Android Server - RRutors
How can i comment inside xml file in android studio?
ERR_ACCESS_DENIED in Android Webview with sdk 30
What is Android?
How to get complete address from latitude and longitude?
What is Application?
What is NetworkOnMainThread Exception?
Key Points to remember while develop the Android Application.
How to convert DP to Pixel and Pixel to Dp?
What is the difference between match_parent and fill_parent?
What is ANR? How to avoid and resolve it?
How do i load image from drawable folder in Jetpack Compose?
How to save activity State in Android?
What is "shared preferences" in Android ?
Permission denied for window type 2010 in Marshmallow device
How to check Android version?
Explain Fragment Life Cycle
How to avoid multiple button click at same time in android?
What is Context?
How to get an image resource by it's name in android?
Set Activity to Fullscreen Mode in Android - RRutors
What is ANR in android?
FragmentPagerAdapter deprecated, Since API 27.1.0 FragmentPagerAdapter is deprecated.
Hide/Disable soft keyboard on Activity launch: Android
How to validate email address in Android with Kotlin?
What is the Different Between val and var in Kotlin?
How to copy database from assets folder in android using kotlin
How to find Android Device UDID or unique ID?
How to install/ uninstall apk by command line ADB
Add Jar/Library Files as Dependency in Android Studio