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 ANR in android?
How to avoid multiple button click at same time in android?
What is Application?
How to validate email address in Android with Kotlin?
How to install/ uninstall apk by command line ADB
How to Generate signed apk with android studio
How to stop EditText focus at Activity startup in Android?
ERROR Android emulator gets killed when I try to run my application and choose an emulator it ret
Explain Fragment Life Cycle
Android Activity FullScreen - How to set activity to fullscreen mode in Android?
How to Exit android app on back pressed?
Check List for Generate Signed APK Android
What is Context?
What is the difference between match_parent and fill_parent?
How to extract date and time from Long type variable in Kotlin on Android "
How to convert milli seconds to hours, minutes and seconds in Android?
What is the Different Between val and var in Kotlin?
FragmentPagerAdapter deprecated, Since API 27.1.0 FragmentPagerAdapter is deprecated.
How do I check in SQLite whether a table exists?
What are symmetric and asymmetric encryption in the way Android interacts with the server?
How to get an image resource by it's name in android?
How to Get bitmap from drawable: Android
How to check Android version?
Android FCM not receiving notifications when app is removed from background
How to start a new activity on button click
How to reduce APK package size?
Key Points to remember while develop the Android Application.
What is ANR? How to avoid and resolve it?
'constructor Handler()' is deprecated. Deprecated in Java, How to use Handler() class in And
How to add jar/library files as a dependency in Android studio gradle file
Google play store rejected my app due to SMS permission I removed SMS permission from the manifes
How can i comment inside xml file in android studio?
How to find Android Device UDID or unique ID?
Android Studio project R can't find
Duplicate files during packaging of APK” build.gradle issue: Android Studio
ERR_ACCESS_DENIED in Android Webview with sdk 30
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
How to save activity State in Android?
INSTALL_FAILED_INVALID_APK: Split lib_slice_9_apk was defined multiple times. It is possible that th
Hide/Disable soft keyboard on Activity launch: Android