最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

android - Do separate processes share a main thread? - Stack Overflow

programmeradmin0浏览0评论

I have an Android app with a few components, each set to run in their own processes:

  1. The activities
  2. A content provider
  3. Foreground service
  4. Accessibility service

I've noticed that heavy work being done in the main thread of the activities or content provider also blocks my services (at least the accessibility service). For example, the accessibility service stops receiving events from the system as I move through different apps. Granted I need to move that work off of the main/UI thread, but how is it affecting my services in separate processes? Do separate processes share a "main" thread?

I have an Android app with a few components, each set to run in their own processes:

  1. The activities
  2. A content provider
  3. Foreground service
  4. Accessibility service

I've noticed that heavy work being done in the main thread of the activities or content provider also blocks my services (at least the accessibility service). For example, the accessibility service stops receiving events from the system as I move through different apps. Granted I need to move that work off of the main/UI thread, but how is it affecting my services in separate processes? Do separate processes share a "main" thread?

Share Improve this question edited Nov 22, 2024 at 0:58 Flyview asked Nov 21, 2024 at 6:36 FlyviewFlyview 1,9591 gold badge29 silver badges51 bronze badges 1
  • As it is technically not possible that multiple processes have access to the same thread I think your actual question is if there is some synchronization between the main threads of different apps. Thus if one main thread can somehow block or slow down the main thread of other apps. – Robert Commented Nov 21, 2024 at 8:23
Add a comment  | 

1 Answer 1

Reset to default 2

Do separate processes share a "main" thread?

No. Threads are owned by a process in all *nix systems, including Android.

I've noticed that heavy work being done in the main thread of the activities or content provider also blocks my services (at least the accessibility service)

We have no information on how you came to this conclusion, or even the definition of "blocks my services".

how is it affecting my services in separate processes?

If nothing else, "heavy work" is going to take up CPU time. Your foreground UI process is going to be given the highest priority from a CPU utilization standpoint. So, it may be that the "heavy work" is not blocking your other processes, but it is starving them of CPU time.

Beyond that, if that "heavy work" is preventing you from updating the UI, it stands to reason that an AccessibilityService is not going to get information about UI updates, since there are no updates. However, that gets back to the "we have no information on how you came to this conclusion" aspect of your question, as I am having to take guesses as to what your actual symptoms are. If you need further assistance, I recommend that you ask a separate Stack Overflow question with a minimal, complete, and verifiable example.

发布评论

评论列表(0)

  1. 暂无评论