哪个线程运行的ContentProvider? [英] Which thread runs ContentProvider?

查看:1074
本文介绍了哪个线程运行的ContentProvider?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我从一个活动,该线程的ContentProvider运行?调用ContentProvider的

If I call to a ContentProvider from a Activity, which thread is ContentProvider running in?

例如。如果活动被杀死,会发生什么以及执行查询时在ContentProvider?说你有一个缓慢的网络查询f.ex。

E.g. What happens if the Activity is killed and a query is executing in the ContentProvider? Say that you have a slow network query f.ex.

推荐答案

如果你指的是在正常使用情况下使用ContentResolver的调用ContentProvider的那么这里是根据我所知,会发生什么:

If you mean the normal use case of using a ContentResolver to call a ContentProvider then here is what happens according to the best of my knowledge:

  1. 我假设在这个例子中,你的ContentProvider生活在一个进程和你在另一个进程的活动。

  1. I am assuming in this example that your ContentProvider lives in one process and your Activity in another process.

如果该ContentProvider的尚未创建那么的onCreate()方法是使用应用程序的进程的主线程调用。

If the ContentProvider has not been created then the onCreate() method is called using the "main" thread of the application's process.

查询()/插入()/更新()/删除()方法使用围坐在每一个应用程序等待来自其他进程的传入命令BinderThreads调用。

The query()/insert()/update()/delete() methods are called using BinderThreads that sit around in every application process waiting for incoming commands from other processes.

如果触发该查询()/插入()活动的/ etc在这些方法调用之一的中间杀了那么会发生什么?我不能肯定地说,但我相当有信心,无论发生在ContentProvider将继续,因为ContentProvider的进程应该继续受到影响,但是会发生什么,该方法返回后,我不能肯定地说。

So what happens if the Activity that triggered the query()/insert()/etc is killed in the middle of one of these method calls? I can't say for certain but I'm fairly confident that whatever is happening in the ContentProvider will continue because the ContentProvider process should go on unaffected but what happens after that method returns I can't say for certain.

我不知道如何慢速网络将参与这一水平,除非你的内容提供者通过网络,而不是通常的SQLite数据库的支持?

I'm not sure how a slow network would be involved in this at all unless your content provider is backed by a network instead of the usual sqlite db?

澄清:

有调用ContentProvider的功能时,有两种可能性(查询/插入/更新/删除/等):

There are two possibilities when invoking a ContentProvider function (query/insert/update/delete/etc):

  1. 您的ContentProvider是在相同的过程调用者。如果是这样的ContentProvider的功能同步运行在同一个线程调用者。

  1. Your ContentProvider is in the same process as the caller. If so the ContentProvider function runs synchronously on the same thread as the caller.

您的ContentProvider是在不同的过程调用者。如果是这样的ContentProvider的函数在ContentProvider过程中的粘合剂线程运行。

Your ContentProvider is in a different process as the caller. If so the ContentProvider function runs on a binder thread in the ContentProvider process.

在这两种情况下,调用者被阻塞,直到ContentProvider的函数返回。与往常一样阅读谷歌和/或AOSP源$ C ​​$ C完整的文档。

In both cases the the caller is blocked until the ContentProvider function returns. As always read the full documentation from Google and/or the AOSP source code.

http://developer.android.com/reference/android/content/ ContentProvider.html http://developer.android.com/guide/topics/providers /content-provider-basics.html http://developer.android.com/guide/components/processes-and -threads.html

这篇关于哪个线程运行的ContentProvider?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆