即使设置了FLAG_NO_CREATE,为什么PendingIntent也会触发onCreate [英] Why does a PendingIntent trigger onCreate even though FLAG_NO_CREATE is set
问题描述
我的一个活动启动AsyncTask
并将正在进行的通知添加到通知区域.此通知从AsyncTask
内部接收更新.
One of my Activities starts an AsyncTask
and adds an ongoing notification to the notification area. This notification receives updates from within the AsyncTask
.
我这样做是为了使用户能够通过主页"按钮离开活动",并且在长时间运行的操作期间仍能接收进度更新.
I did this so the users are able to leave the Activity with the Home button and still receive progress updates during a long running operation.
单击通知应使用户返回此活动.问题是,无论如何,看来似乎不再使用旧的活动,而是实例化了新的活动(而AsyncTask
仍在运行).每次单击通知时,都会调用此活动的onCreate
方法.
Clicking the notification should return the user to this activity. The problem is that no matter what, it seems that the old activity is never used again, but instanciated new (while the AsyncTask
still runs). The onCreate
method of this activity gets called every time the notification gets clicked.
我尝试使用FLAG_NO_CREATE
和FLAG_UPDATE_CURRENT
选项,但没有任何区别.
I tried using the FLAG_NO_CREATE
and FLAG_UPDATE_CURRENT
options, but it doesn't make any difference.
处理这种情况的正确方法是什么?我正在开发API级别4.
What is the correct way to handle this situation? I'm developing for API level 4.
推荐答案
我这样做是为了让用户能够 将活动留在家中 按钮,但仍会收到进度 长期运行中更新 操作.
I did this so the users are able to leave the Activity with the Home button and still receive progress updates during a long running operation.
听起来应该使用服务.
问题在于,无论如何 似乎旧的活动从来没有 再次使用,但实例化了新的
The problem is that no matter what, it seems that the old activity is never used again, but instanciated new
是的. Android可能会杀死您的活动.您绝对不能保证调用onStop后活动会发生什么.
Yes. Android probably killed your activty. You have ABSOLUTELY NO guarantee what happens to your activity after its onStop is called.
我正在为API级别4开发
I'm developing for API level 4
您为4写作的任何特殊原因是什么?那已经很老了,现在大多数手机都使用2.0.
Any particular reason you're writing for 4? That's pretty old and most phones are on 2.0 now.
这篇关于即使设置了FLAG_NO_CREATE,为什么PendingIntent也会触发onCreate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!