asynchronous - Android background processing, handle result and Activity lifecycle -


i have general problem android background processing, how deal it?

imagine scenario:

  1. users starts activity fragment.
  2. fragments starts fetching data network using intenservice.
  3. intentservice provide result fragment via localbroadcast system.

enter image description here

broadcastreciever in fragment registered/unregistered in onresume()/onpause(). looks good, when user press home button right after 2) result broadcast intentservice has been lost. happen becouse fragment unregistered broadcastreceiver in onpasue() callback.

there general pattern avoid issue? using resultreceiver instead of broadcastreceiver better prupouse?

i have tired resultreceiver, in case send resultreceiver service in bundle (it implements parcelable interface) after recreation activity due changing screen orientation resultreceiver has "dirty" reference previusly created activity can cause bugs.

your intentservice can create notification on task completion, pending intent activity, in case activity goes background before receiving task completion broadcast.

if thinking launching activity on task completion, after user exits app (via home or button), not suggested ui pattern. android developer website:

a status bar notification should used case in background service needs alert user event requires response. background service should never launch activity on own in order receive user interaction. service should instead create status bar notification launch activity when selected user.


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -