1

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.

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.

I tried using the FLAG_NO_CREATE and FLAG_UPDATE_CURRENT options, but it doesn't make any difference.

What is the correct way to handle this situation? I'm developing for API level 4.

4

1 回答 1

1

我这样做是为了让用户能够使用 Home 按钮离开 Activity,并且在长时间运行的操作期间仍会收到进度更新。

听起来你应该使用服务。

问题是无论如何,旧的活动似乎再也没有使用过,而是实例化了新的

是的。Android 可能扼杀了您的活动。您绝对不能保证在调用 onStop 后您的活动会发生什么。

我正在为 API 级别 4 开发

你写 4 有什么特别的原因吗?那已经很老了,现在大多数手机都在 2.0 上。

于 2011-01-13T18:19:24.517 回答