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 is Context?
What are Android Versions available?
How to convert milli seconds to hours, minutes and seconds in Android?
Android Activity FullScreen - How to set activity to fullscreen mode in Android?
ERROR Android emulator gets killed when I try to run my application and choose an emulator it ret
FragmentPagerAdapter deprecated, Since API 27.1.0 FragmentPagerAdapter is deprecated.
How to avoid multiple button click at same time in android?
How to copy database from assets folder in android using kotlin
What is ANR in android?
How to stop EditText focus at Activity startup in Android?
INSTALL_FAILED_INVALID_APK: Split lib_slice_9_apk was defined multiple times. It is possible that th
How to Get bitmap from drawable: Android
What is Android?
How to save activity State in Android?
What happens next when the device switches between portrait and landscape?
How to check Android version?
How do i load image from drawable folder in Jetpack Compose?
How to extract date and time from Long type variable in Kotlin on Android "
What are symmetric and asymmetric encryption in the way Android interacts with the server?
Duplicate files during packaging of APK” build.gradle issue: Android Studio
How to Exit android app on back pressed?
What is ANR? How to avoid and resolve it?
Check List for Generate Signed APK Android
How to start a new activity on button click
How to get complete address from latitude and longitude?
What is the difference between match_parent and fill_parent?
What is Intent? What is the difference between an implicit intent and an explicit intent?
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
Permission denied for window type 2010 in Marshmallow device
Invoke-customs are only supported starting with android 0 --min-api 26
ERR_ACCESS_DENIED in Android Webview with sdk 30
What is Application?
What is NetworkOnMainThread Exception?
How do I generate random numbers in Dart?
What is the Different Between val and var in Kotlin?
How to get screen size (width,height) in Android?
'constructor Handler()' is deprecated. Deprecated in Java, How to use Handler() class in And
Error: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1 path
What is "shared preferences" in Android ?
How to validate email address in Android with Kotlin?