简体   繁体   English

在没有UI的情况下在后台运行Activity

[英]Run Activity in background without UI

In my application, I want to use stealth mode so that the service which is containing some activities in it will be running in the background. 在我的应用程序中,我想使用隐身模式,以便其中包含某些活动的服务将在后台运行。 But at the same time on certain guesture or some combination of keys I need to start another activity which will be having some UI in it.Is this possible?? 但是同时出于某种喜好或某些按键组合,我需要启动另一个将在其中包含UI的活动,这可能吗? If so please let me know I have tried using longpress on screen but it needs an activity running, in order to start another activity,whereas when I tried to override the home button or menu button it again needs an activity running in the front to enable long press. 如果是这样,请让我知道我已经尝试过在屏幕上使用longpress了,但是它需要运行一个活动才能启动另一个活动,而当我尝试覆盖主屏幕按钮或菜单按钮时,它又需要在前面运行一个活动来启用长按。 Is there a way wherein I can make use of guesture listener through service or without making use of activity. 有没有一种方法可以通过服务或不使用活动来利用来宾监听器。 Please suggest me a good solution for this problem because I have been searching a lot for the same. 请为我提出一个解决此问题的好方法,因为我一直在搜索相同的内容。

The SDK does not allow this for security reasons, as a malicious app could intercept a user's touch events and absorb them, rendering any other feature of the device useless. 出于安全原因,SDK不允许这样做,因为恶意应用程序可能会拦截用户的触摸事件并吸收它们,从而使设备的任何其他功能失效。

You could however have your app listen for shake events and launch your activity upon the user shaking the device from a Service. 但是,您可以让您的应用监听震动事件,并在用户从服务中震动设备时启动您的活动。

I think Android notifications suit well for your needs. 我认为Android通知非常适合您的需求。 You can "inject" your service's icon into Android screen, and react to interactions with user. 您可以将服务的图标“注入”到Android屏幕中,并对与用户的互动做出反应。 You may find answers on SO, which demonstrate how to launch an activity from a notification. 您可能会在SO上找到答案,这些答案演示了如何从通知中启动活动。 Here is one example . 这是一个例子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM