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();
Android Studio project R can't find
How to save activity State in Android?
What is Application?
How to reduce APK package size?
Add Jar/Library Files as Dependency in Android Studio
How do I generate random numbers in Dart?
How to Generate signed apk with android studio
How to avoid multiple button click at same time in android?
FragmentPagerAdapter deprecated, Since API 27.1.0 FragmentPagerAdapter is deprecated.
How to validate email address in Android with Kotlin?
Fix Behavior Subclass BottomSheetBehavior Exception - RRutors
How to install/ uninstall apk by command line ADB
How to convert milli seconds to hours, minutes and seconds in Android?
How to get a contact image using a phone number in android?
What is the Different Between val and var in Kotlin?
How to get an image resource by it's name in android?
What happens next when the device switches between portrait and landscape?
Key Points to remember while develop the Android Application.
Fix Play Store Rejection Due to SMS Permission - RRutors
Permission denied for window type 2010 in Marshmallow device
What are Android Versions available?
How can i comment inside xml file in android studio?
How To Set Text Color Programmatically Android TextView?
Symmetric vs Asymmetric Encryption in Android Server - RRutors
What is Android?
Explain Fragment Life Cycle
How to get screen size (width,height) in Android?
How to convert DP to Pixel and Pixel to Dp?
Fix Error: Use JsonReader.setLenient(true) for Malformed JSON
ERR_ACCESS_DENIED in Android Webview with sdk 30
INSTALL_FAILED_INVALID_APK: Split lib_slice_9_apk was defined multiple times. It is possible that th
What is ANR in android?
How to start a new activity on button click
How do i load image from drawable folder in Jetpack Compose?
How to find Android Device UDID or unique ID?
How to copy database from assets folder in android using kotlin
Decompile APK Files: How to Get Source Code - RRutors Guide
What is Context?
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
How to Exit android app on back pressed?