Android的应用服务,新手的好奇心 [英] Android Using Services , newbie's curiosity
问题描述
我想了解服务的一些基本,实用,东西,没有明确的Android开发者参考页提到的。
-
我如何可以调用其他应用服务,这还没有开始?
-
我如何查询由其他应用程序提供哪些服务?
-
服务是否允许使用的用户界面的方法呢? (文档说,他们是专门指不具有用户界面给用户,但他们的例子有一个土司吧)
-
是服务重入? (如果两个应用程序调用相同的服务,他们会在同一时间'服务'没有与任何局部变量搞乱)
-
是服务插件制作方式?
-
我可以使用服务致以已安装应用程序的功能? (即我可以安装只是一个服务
- 可以开展的服务活动正常?他们可能会导致他们的客户来完成?
结果
我如何可以调用其他应用服务,这还没有开始?
块引用>之类的活动服务是通过使用
意图
系统启动。你可以开始使用startService(意向)的服务;
方法。这个跨越应用程序边界只要服务是否正确配置为从它自己的沙箱外部的回答意图。
我如何查询由其他应用程序提供哪些服务?
块引用>文档。我无法想象一个情况下,你会想询问一个应用程序为它提供的服务的没有的文档,你会不知道如何才能得到正确执行服务通过。
服务是否允许使用的用户界面的方法呢? (文档说,他们是专门指不具有用户界面给用户,但他们的例子有一个土司吧)
块引用>服务可以访问应用程序上下文(因此可以发布
吐司
s或启动活动
的自己) 。它们也可以具有在同一沙箱中运行该应用的可见性,这意味着,通过处理程序的手段,他们可以直接改变运行活动的用户界面。就其性质不过服务
设计没有,即使有可能的UI接口。
是服务重入? (如果两个应用程序调用相同的服务,他们会在同一时间'服务'没有与任何局部变量搞乱)
块引用>服务可以用不同的标志启动(可以进行不同的编程),让他们服务收到
意图
以异步方式还是要排队意图
进行串行执行。你可以找到更多关于这(和你的问题这里)
是服务插件制作方式?
块引用>插件?
我可以使用服务致以已安装应用程序的功能? (即我可以安装只是一个服务
块引用>您可以安装一个服务作为一个单独的应用程序,它可以捕获
startService()
调用它使,如果它不使用一个名为意图
。此服务将是一个不过不同的沙箱,不会有访问正在运行的应用程序的变量/状态。
能否推出的服务活动正常?他们可能会导致他们的客户来完成?
块引用>是的,如果服务是在同一个沙箱中运行它们都可以运行沿着它的应用的可见性。它可以使用
startActivity()
,因为它可以访问应用程序上下文,它可以调用内部的应用程序(其中可能包含静态接入的静态方法活动
)。I want to know some basic, practical, things about Services, that are not explicitly mentioned in the Android Developers reference pages.
How can I call a service from another app, that has not even started?
How do I query which services are provided by other applications?
Are services allowed to use UI methods? (the documentation says they are specifically meant not to have UI to the user, but their example has a Toast in it)
Are services re-entrant? (if two apps call the same service, will they be 'serviced' at the same time without messing with any local variable)
Are services the way plug-ins are made?
Can I use a service to extend the functionality of my already installed app? (i.e. can I 'install' just a service
- Can services launch normal activities? Can they cause their clients to finish?
解决方案How can I call a service from another app, that has not even started?
Services like Activities are started through use of the
Intent
system. You can start a service using thestartService(intent);
method. This crosses application boundaries as long as the service is properly configured to answer intents from outside of it's own sandbox.How do I query which services are provided by other applications?
Documentation. I can't imagine a situation where you would want to interrogate an app for it's services without the documentation as you wouldn't know what to pass in order to get the service to perform correctly.
Are services allowed to use UI methods? (the documentation says they are specifically meant not to have UI to the user, but their example has a Toast in it)
Services have access to the application context (and therefore can post
Toast
s or startActivities
of their own). They may also have visibility of the app running in the same sandbox, this means that by means of handlers they can change the UI of the running Activity directly. By their nature howeverServices
are not designed to interface with the UI even though it's possible.Are services re-entrant? (if two apps call the same service, will they be 'serviced' at the same time without messing with any local variable)
Services can be started with different flags (and can be programmed differently) to allow them to service received
Intents
in an asynchronous way or to queue theIntents
to be performed serially. You can find more about this (and the rest of your question here)Are services the way plug-ins are made?
Plugins?
Can I use a service to extend the functionality of my already installed app? (i.e. can I 'install' just a service
You can install a service as a seperate app which can catch
startService()
calls it's making if it isn't using a namedIntent
. This service would be in a different sandbox however and wouldn't have access to the running app's variables/state.Can services launch normal activities? Can they cause their clients to finish?
Yes, if the Service is running in the same sandbox they can have visibility of the App running alongside it. It can use
startActivity()
as it has access to application context and it can call static methods inside of the app (which could contain static access to theActivity
).这篇关于Android的应用服务,新手的好奇心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!