Sporadic IllegalArgumentException: Unknown URL: //

Very rarely it turns out:

Fatal Exception: java.lang.IllegalArgumentException: Unknown URL content://com.example.provider/info at android.content.ContentResolver.insert(ContentResolver.java:1252) Fatal Exception: java.lang.IllegalArgumentException: Unknown authority com.example.provider at android.content.ContentResolver.applyBatch(ContentResolver.java:1247) 

The emphasis is on rarely. As a rule, they work normally, without problems, therefore the authorities are well-disposed, but this is manifested every time for no reason. Are there reasons why ContentResolver cannot find the ContentProvider (i.e. if it is not already configured)?

+5
source share
1 answer

I had a rare IllegalArgumentException problem with Unknown URIs when I was ContentResolver operations in a custom Application object.

For example, I tried to remove items in my content provider in an onCreate application, which could crash very rarely :

 public class CustomApplication extends Application { @Override public void onCreate() { //.. context.getContentResolver().delete(ReminderEntry.getContentURI(), null, null, null, null); //.. } } 

That would sometimes lead to the following failure:

 Fatal Exception: java.lang.RuntimeException: Unable to create application com.myapp.CustomApplication: java.lang.IllegalArgumentException: Unknown URL content://com.myapp.db.CustomContentProvider/reminder at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6431) at android.app.ActivityThread.access$1800(ActivityThread.java:229) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1887) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:7331) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) Caused by java.lang.IllegalArgumentException: Unknown URL content://com.myapp.db.CustomContentProvider/reminder at android.content.ContentResolver.delete(ContentResolver.java:1376) at com.myapp.ReminderEntryDao.delete(Unknown Source) at com.myapp.CustomApplication.onCreate(Unknown Source) at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1037) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6428) at android.app.ActivityThread.access$1800(ActivityThread.java:229) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1887) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:7331) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 

I also saw similar behavior with the BOOT_COMPLETE receiver. I had about 70 accident reports with this exception (mainly Infinix devices ~ 43%, hardly any Samsung devices), about 200,000 active users per month. IllegalArguementException Device Stats

I moved this to a background given job and have not seen a glitch since. I could only ever reproduce this problem once on a Nexus device that I used, but never again.

I suspect that sometimes on some versions of Android on some devices the Application / BOOT_COMPLETE initialized before the ContentProvider fully initialized, and therefore, when it tries to access it, it is not yet configured.

There are several stackoverflow posts that determine exactly what was created first and what it should look like < operating system:

Is an instance of the Application class guaranteed before a specific boot receiver is issued

But, as I said, I saw something else, and moving the operations from classes to background schedulers seems to fix the problem (maybe this is just because it takes a little longer to configure). Hope my experience helps you.

Edit: I used the evernote task manager and deferred my ContentResolver operations to the task, if necessary. (but I would suggest that delaying the operation of the content provider for any background processing might fix it, because it had a bit more time to install - this, of course, is my suspicion).

 class DeleteRemindersJob extends Job { @NonNull @Override protected Result onRunJob(final Params params) { cursor = getContext().getContentResolver().delete(ReminderEntry.getContentURI(), null, null, null, null); //.. return Result.SUCCESS; } } 
+4
source

Source: https://habr.com/ru/post/1262322/


All Articles