简体   繁体   English

如果向其活动不可见的处理程序发送消息会发生什么?

[英]What will happen if send message to handler whose activity has been unvisible?

我在activity onCreate方法中创建了一个处理程序,并启动一个后台线程。在后台线程中,我将调用处理程序的sendMessage方法(在处理程序的handleMessage方法中,我更新了活动的UI),但是活动可能是不可见的,会是什么发生?

If you don't do anything UI-related in that handler, it'll execute fine. 如果你在该处理程序中没有做任何与UI相关的事情,那么它将执行得很好。 Keep in mind that holding references to inactive Activity could create a memory leak - you'll prevent the VM from collecting unused resources. 请记住,保持对非活动Activity的引用可能会造成内存泄漏 - 您将阻止VM收集未使用的资源。

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

相关问题 发送消息未到达活动中的处理程序 - send message not reaching the handler in activity 如果Handler在Looper.prepare()之后但在调用Looper.loop()之前将消息发布到线程会发生什么? - What happens if a Handler posts a message to a thread after Looper.prepare() but before Looper.loop() has been called? 如果已收到来自服务的消息,则通知活动 - Notify Activity if a message has been received from Service 使用onNewIntent和活动生命周期来验证是否已看到消息 - Using onNewIntent and activity lifecycle to verify if a message has been seen 当活动崩溃时会发生什么? - What happen when the activity crash? 定期向处理程序发送消息 - Send a message to a handler periodically 在Android OS销毁某个活动之后,对活动的引用会如何处理? - What happens to references to an activity after it has been destroyed by the Android OS? 在聊天活动中删除消息没有任何反应 - Delete message in chat activity nothing happen Android 处理程序在活动被销毁后仍会继续运行一段时间 - Android Handler keeps running for a while even after the activity has been destroyed 如果退出正在处理的循环程序,处理程序将如何处理? - What will happen to a handler if the looper it is handling is quit?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM