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();
Set Activity to Fullscreen Mode in Android - RRutors
What is the difference between match_parent and fill_parent?
How to save activity State in Android?
What is Intent? What is the difference between an implicit intent and an explicit intent?
How to get complete address from latitude and longitude?
Explain Fragment Life Cycle
What are Android Versions available?
How to install/ uninstall apk by command line ADB
Decompile APK Files: How to Get Source Code - RRutors Guide
How to find Android Device UDID or unique ID?
How to stop EditText focus at Activity startup in Android?
Hide/Disable soft keyboard on Activity launch: Android
How to Exit android app on back pressed?
What is Application?
How To Set Text Color Programmatically Android TextView?
What is ANR? How to avoid and resolve it?
Fix Android Emulator Kill Error When Running Your App
What is Android Fragments?
Open PDF in Google Drive with Intent in Android - RRutors
Permission denied for window type 2010 in Marshmallow device
Fix Duplicate Files in APK Build.gradle Issue - RRutors
INSTALL_FAILED_INVALID_APK: Split lib_slice_9_apk was defined multiple times. It is possible that th
Key Points to remember while develop the Android Application.
How do I check in SQLite whether a table exists?
What is Android?
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
What is the Different Between val and var in Kotlin?
FCM Not Receiving Notifications in Android - RRutors
How do I generate random numbers in Dart?
Android Studio project R can't find
How to reduce APK package size?
How do i load image from drawable folder in Jetpack Compose?
How to Get bitmap from drawable: Android
How to get screen size (width,height) in Android?
How to copy database from assets folder in android using kotlin
How to check Android version?
Check List for Generate Signed APK Android
How to convert milli seconds to hours, minutes and seconds in Android?
How to get a contact image using a phone number in android?
Fix Behavior Subclass BottomSheetBehavior Exception - RRutors