我的一个 Activity 启动了一个 AsyncTask
并向通知区域添加了一个正在进行的通知。此通知从 AsyncTask
中接收更新。
我这样做是为了让用户能够使用主页按钮离开 Activity,并且在长时间运行的操作期间仍能收到进度更新。
点击通知应该让用户返回到这个 Activity 。问题是,无论如何,旧 Activity 似乎再也不会被使用,而是实例化为新 Activity (而 AsyncTask
仍在运行)。每次单击通知时都会调用此 Activity 的 onCreate
方法。
我尝试使用 FLAG_NO_CREATE
和 FLAG_UPDATE_CURRENT
选项,但没有任何区别。
处理这种情况的正确方法是什么?我正在为 API 级别 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 可能会杀死您的 Activity 。您绝对不能保证在调用 onStop 后您的 Activity 会发生什么。
I'm developing for API level 4
您为 4 写作有什么特别的原因吗?那太旧了,现在大多数手机都在 2.0 上。
关于android - 为什么即使设置了 FLAG_NO_CREATE,PendingIntent 也会触发 onCreate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4683619/