0

I am new to Android application development and I am currently working on an existing Android application. From the Android documentation link https://developer.android.com/distribute/best-practices/develop/target-sdk it says that app updates must target at least Android 9.0.

So, I have set my targetSDKVersion to 28 and tried to run the application but restartLoader is not working as expected. The application is getting closed immediately when it tries to access the following line in the code.

this.getLoaderManager().restartLoader(1, params, this); 

It works fine when I set the targetSDKVersion to 27. I have also found that the LoaderManager is deprecated in API level 28 and they have suggested to use the Support Library as mentioned in the link https://developer.android.com/reference/android/app/LoaderManager.

So I have migrated the entire project to AndroidX such that the restartLoader works fine but I am getting the same issue. I have made many changes to the dependencies of the build.gradle file as the one shown below but still the restartLoader is not working. I have tried setting many dependencies but it is of no use.

dependencies {
    //implementation files('libs/android-support-v13.jar')
    implementation "com.android.support:loader:28.0.0-alpha1"
    implementation "com.android.support:support-fragment:28.0.0"
}

How can I fix the issue that is getting occurred when trying to access the restartLoader()?

halfer
  • 19,824
  • 17
  • 99
  • 186
Kamal
  • 453
  • 1
  • 10
  • 22
  • Can you share crash log?. – Olcay Ertaş Oct 22 '19 at 10:28
  • "application closes" show stack trace – EpicPandaForce Oct 22 '19 at 10:30
  • As i am new to this entire development process, i am not aware where it exists. Can you please let me know where can i get these logs/stack trace? – Kamal Oct 22 '19 at 10:32
  • Here is a link about logging in Android Studio, which will help you to get a crashlog that then will help you to determine the error or help us (if you add it) to help you to determine the error: https://developer.android.com/studio/debug/am-logcat – Traendy Oct 22 '19 at 10:38
  • @Traendy I found the errors that is causing the crash. are as follows "Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/impl/client/DefaultHttpClient;" and Caused by: java.lang.ClassNotFoundException: Didn't find class "org.apache.http.impl.client.DefaultHttpClient"... Can you please let me know what is causing this issues? – Kamal Oct 22 '19 at 10:48
  • Please read [Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers?](//meta.stackoverflow.com/q/326569) - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions. – halfer Oct 22 '19 at 19:52

1 Answers1

0

You are trying to use legacy HTTP client when you try to use loader. You should add below code to your AndroidManifest.xml:

<uses-library android:name="org.apache.http.legacy" android:required="false"/>

You can get more details from here.

Olcay Ertaş
  • 5,987
  • 8
  • 76
  • 112
  • Yeah i found the cause and made necessary changes but this time i received the error as "Cleartext traffic not permitted:" . So i have added android:usesCleartextTraffic="true" in the AndroidManifiest.xml file and it is working fine. My concern is can we use that attribuet "usescleartextTraffic"? Please suggest – Kamal Oct 22 '19 at 11:37
  • if you don't mind security on your application you can use it, or you can use it while developing your application and use a secure api when you release it. – Olcay Ertaş Oct 22 '19 at 12:19
  • Is there any other alternative in fixing the "Cleartext traffic not permitted" issue? If so can you please suggest – Kamal Oct 22 '19 at 12:40