是否可以中断 finish()
我有一个以 SingleTask 模式(Android 2.2)运行的活动,它接收来自其他活动或服务的意图。我的活动将每个收到的意图推送到队列中并对其执行某些操作。完成后,如果没有任何要处理的意图(即队列为空),它将调用 finish()。
问题是当它在调用 finish() 后立即收到意图时:调用 onNewIntent 和 onResume 方法,但我的 Activity 随后被 Android 销毁(onPause/onDestroy),并且该意图未得到处理。
我知道这是一个相当顽皮的场景,但我对这种行为感兴趣......所以问题是:是否可以在调用 finish() 后中断 finish() 和/或恢复活动?
谢谢!
I have an activity running in SingleTask mode (Android 2.2) which receives intents from other activities or services. My activity pushes each received intent into a queue and does something with it. On completion, if there isn't any intent left to process (i.e. the queue is empty) it calls finish().
The problem is when it receives an intent immediately after finish() has been called: the onNewIntent and onResume methods are called, but my activity is then destroyed (onPause/onDestroy) by Android and the intent is not processed.
I know that this is quite a naughty scenario, but I'm interested in this kind of behaviour... so the question is: is it possible to interrupt finish() and/or resume the activity after finish() has been called?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
听起来您正在尝试重新创建 IntentService
It sounds like you're trying to re-create an IntentService
在调用 finish() 时,将调用 onDestroy() 方法,然后您的活动就死了:)
该活动可以通过某种意图再次启动,但将调用 oncreate 而不是 onNewIntent
重要注意事项是,在之间无法接收意图finish() 语句和 onDrestroy 方法!
因此,如果调用完成,那么您的活动的每个新意图都会调用 onCreate(),
因此您不必担心,
您不应该尝试中断完成,这是不可能的,因为它是原子操作
但是您需要检查您的逻辑并增强您的 oncreate 和 onNewIntent 方法以优雅地处理您的场景
on call to finish() the onDestroy() method is called and than you activity is dead :)
this activity can be started again by some intent, but the oncreate will be called not onNewIntent
Important note is that the intent can not be received between the finish() statement and onDrestroy method !
so if the finish is called then every new intent for your activity will result with call to onCreate()
so you do not to be worried
you should not try to interrupt finish that is not possible cause it is atomic operation
But you need to review you logic and enhance your oncreate and onNewIntent method to gracefully handle your scenario
从 onNewIntent 开始活动。
Start activity from onNewIntent.