简体   繁体   English

Android和后台进程

[英]Android and background processes

I wrote an bluetooth app with my bt-connection established in a service, so the connection is still alive when I minimize my app. 我编写了一个在应用程序中建立了bt-connection的蓝牙应用程序,因此当我最小化我的应用程序时,该连接仍然有效。

But when watching my task manager, my app is still there. 但是当观看我的任务管理器时,我的应用仍然存在。 And when calling onDestroy in my app, I have to stop my Service. 当我在应用程序中调用onDestroy时,我必须停止服务。

But other apps like telegram or skype (whatsapp too I think) aren't in my task-manager visible but by having an incoming message they notify me nevertheless. 但是其他应用程序(例如电报或skype)(我也认为是whatsapp)在我的任务管理器中不可见,但是通过收到传入消息,它们仍会通知我。

How is this even possible? 这怎么可能? How can I write my bluetooth connection like this, that I can really close my app and anyway the incoming messages will be handled? 我该如何编写我的蓝牙连接,这样我才能真正关闭我的应用程序并且无论如何都会处理传入的消息?

The other apps might be having some light weight service running in other process which gets the data for the main app.Go to settings->application manager->running processes..you will see all the service.. 其他应用程序可能正在其他进程中运行一些轻量级服务,该服务会获取主应用程序的数据。转到设置->应用程序管理器->运行进程..您将看到所有服务。

Other mechanism which apps use is port-directed sms. 应用程序使用的其他机制是端口定向的短信。 In such a scenario you don't need any service running.However port directed sms doesnt work on all the phone and for all the apps. 在这种情况下,您不需要运行任何服务,但是端口定向的短信无法在所有电话和所有应用程序上正常运行。

When you put remove your application from the foreground, Android keeps the activity on the stack again in case you will go back to it (unless you explicitly destroy the activity). 当您从前台删除应用程序时,Android会将活动再次保留在堆栈中,以防您退回到该活动(除非您明确销毁该活动)。 So this maybe one reason why you still see it in the Task Manager. 因此,这也许就是您仍在任务管理器中看到它的原因之一。 You cannot kill entirely the app and it will still post messages. 您无法完全杀死该应用程序,它仍会发布消息。 Your service will be running in the background and it will be visible in the app Manager->Running Services. 您的服务将在后台运行,并且将在应用程序管理器->运行服务中显示。

However if you destroy your activities the app it will not be visible in the app list of the Task Manager. 但是,如果您破坏活动,则该应用程序将在任务管理器的应用程序列表中不可见。

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

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