Android ContentResolver query sometimes not starting ContentProvider process

瘦欲@ 提交于 2020-01-13 03:24:28

问题


I have been implementing my own custom content provider in an app A and want to query its database from a separate app B that calls ContentResolver.query(...) using the appropriate custom URI defined in A.

All goes well when A has been running just before I launch B (thus A's process still running in the background).

However when I kill A's process, then B fails to query A's database! I thought querying a content provider would automatically start its process so the data can be retrieved. Am I missing something?

Some clarifications:

  • I properly set up the content provider. There is no problem with misspellings in the authority string, no problem with permissions, the provider is properly declared in A's manifest with the proper name, authorities, exported and enabled. I went over about any example I could find about custom content providers to absolutely get it right.
  • The package manager tells me the provider is properly registered in the system (even when its process is not running). I verified that using List<PackageInfo> info = context.getPackageManager().getInstalledPackages(PackageManager.GET_PROVIDERS);

  • When B fails to query A's provider, logcat's error message is E/ActivityThread: Failed to find provider info for com.example.provider.MyProvider Neither the constructor nor the onCreate method of A's provider is being called in that case.

  • I tried other query methods using a ContentProviderClient, a CursorLoader, direct query from adb; the behaviour is always the same.

  • I have even created a third app C with a simplistic test content provider (as A is a bit more complex); still the same problem.
  • The problem occurs only when I use my real device, not when I use an emulator (even using the exact same Android version). I am using an Alcatel OneTouch Idol 3, model number 6045Y, running Android 5.0.2, Kernel version 3.10.49.

Any help would be appreciated! Thanks!

来源:https://stackoverflow.com/questions/36883193/android-contentresolver-query-sometimes-not-starting-contentprovider-process

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!