Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BindService呼叫時機 #119

Closed
ArthurPai opened this issue Apr 20, 2016 · 7 comments
Closed

BindService呼叫時機 #119

ArthurPai opened this issue Apr 20, 2016 · 7 comments
Labels

Comments

@ArthurPai
Copy link

只要先呼叫bindService,目前還是會出現進度跳來跳去的狀況
如果不呼叫,讓task#start去bind就不會有這現象

我的測試程式是等程式啟動完後,過了一秒之後才去呼叫bindService

下面是目前看到,會發生這個現象時,Log會出現這些資訊,

FileDownloadEventPool: publish event.download.transfer
FileDownloadTask: ~~~callback -8629196 old[3] new[6] 1
FileDownloadTask: can't update status change by keep flow, 3, but the current status is 3, -8629196
FileDownloadTask: can't update status change by keep ahead, 3, but the current status is 3, -8629196
FileDownloadTask: The flow callback did not consumed, id:-8629196 status:6 task-count:1 | 3
FileDownloadEventPool: publish event.download.transfer
WaitingRunnable: loop: for size 1 4
FileDownloadTask: ~~~callback -8629196 old[3] new[1] 1
FileDownloadTask: can't update status change by keep flow, 3, but the current status is 3, -8629196
FileDownloadTask: can't update status change by keep ahead, 3, but the current status is 3, -8629196
FileDownloadTask: The flow callback did not consumed, id:-8629196 status:1 task-count:1 | 3
FileDownloadEventPool: publish event.download.transfer
FileDownloadTask: ~~~callback -8629196 old[3] new[2] 1
FileDownloadTask: can't update status change by keep flow, 3, but the current status is 3, -8629196
FileDownloadTask: can't update status change by keep ahead, 3, but the current status is 3, -8629196
FileDownloadTask: The flow callback did not consumed, id:-8629196 status:2 task-count:1 | 3

我有去看了一下這部分的code
不過還看不太懂是什麼情形會引起BaseDownloadTask#updateKeepFlow及BaseDownloadTask#updateKeepAhead出現失敗的狀況
可以請問一下,為何會這樣?

@Jacksgong
Copy link
Collaborator

不要在 Application中调用 bindService 如果你要提前 bindService 就在你的Activity中调用。

因此 Application中调用的话,每个进程都会调到。

@Jacksgong
Copy link
Collaborator

你可以参看下,TasksManagerDemoActivity 里面也调用了 bindService 但是没有问题。

@Jacksgong
Copy link
Collaborator

我现在改下代码,这种情况我直接抛异常,来引导使用。

@ArthurPai
Copy link
Author

好,我再抓新本版來測試看看

@Jacksgong
Copy link
Collaborator

@ArthurPai 我可能不会马上发新版本,太频繁了。你注意下不要在 Application#onCreate 中直接调用 bindService 除非你在 Application#onCreate 中调用 bindService之前先判断下进程,把下载进程过滤掉。就可以把你说的这个问题解决了。

@Jacksgong
Copy link
Collaborator

Jacksgong commented Apr 20, 2016

你也可以考虑不要使用多进程模式,这样可以有效减少IPC IO,可以提高下载速度的同时也可以解决你这个问题。

具体如何,你参考下 Wiki 中的 filedownloader.properties 中的 process.non-separate

P.S: 在非多进程模式情况下,由于下载FileDownloadService共享主进程,因此没有下载进程调用 Application#onCreate 的情况,因此,在这种情况下你可以直接在 Application#onCreatebindService

@ArthurPai
Copy link
Author

謝謝,還是找不到為何會有這現象,因為我並不是在Applicatin#onCreate中呼叫bind

我要先bind的目的是為了App重啟時,可以在沒有呼叫過任何BaseDownloadTask#start,也可以得到之前有下載過的tasks的狀態。

現在我的作法是自己管理Tasks的狀態,將notification得到的狀態及sofar記錄到SQLite,下次App重啟時,就先使用DB中的資訊,而不用去bind service。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants