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();
How To Set Text Color Programmatically Android TextView?
How to reduce APK package size?
'constructor Handler()' is deprecated. Deprecated in Java, How to use Handler() class in And
How to copy database from assets folder in android using kotlin
How to get complete address from latitude and longitude?
How to extract date and time from Long type variable in Kotlin on Android "
What is Android Fragments?
How to avoid multiple button click at same time in android?
How to convert DP to Pixel and Pixel to Dp?
FragmentPagerAdapter deprecated, Since API 27.1.0 FragmentPagerAdapter is deprecated.
How to Generate signed apk with android studio
How to start a new activity on button click
What are the notifications available in android?
Duplicate files during packaging of APK” build.gradle issue: Android Studio
How to get a contact image using a phone number in android?
What are symmetric and asymmetric encryption in the way Android interacts with the server?
What is Android?
Permission denied for window type 2010 in Marshmallow device
Hide/Disable soft keyboard on Activity launch: Android
How to save activity State in Android?
How can i comment inside xml file in android studio?
What happens next when the device switches between portrait and landscape?
What is the difference between match_parent and fill_parent?
Key Points to remember while develop the Android Application.
What is "shared preferences" in Android ?
Is There A Way To Get The Source Code From An APK File? (or) How to decompile apk?
ERR_ACCESS_DENIED in Android Webview with sdk 30
Could not inflate Behavior subclass android.support.design.widget. BottomSheetBehavior How resolve
What is the Different Between val and var in Kotlin?
How do I check in SQLite whether a table exists?
How to get screen size (width,height) in Android?
Explain Fragment Life Cycle
Google play store rejected my app due to SMS permission I removed SMS permission from the manifes
Android Activity FullScreen - How to set activity to fullscreen mode in Android?
How to install/ uninstall apk by command line ADB
How do I generate random numbers in Dart?
What is Context?
What is Intent? What is the difference between an implicit intent and an explicit intent?
Intent for Drive PDF Viewer - How to open PDF in Google Drive with intent
How to stop EditText focus at Activity startup in Android?