android - Activity restart on rotation change -


i have activity. activity contains fragment within viewpager. fragment needs copy files (with progressdialog), when rotate screen when busy, activity restarts , stops.

i tried adding android:configchanges="orientation|screensize" androidmanifest wont solution either because adview , toolbar won't reload on rotation change:

before:

after:

(notice difference toolbar , adview height?)

how can keep activity/fragment alive, working toolbar , adview?

thanks

needs copy files

what little people realize android activity , fragment not place execute long running operations, such download stuff internet or copying files.

both activity , fragment ui elements can destroyed, re-created, without of warning.

the correct way of dealing such issue have service execute long running operation, activity or fragment should start service , "bind" it, executing usual unbind , bind again upon rotation.

you can read here service , bounds services: http://developer.android.com/guide/components/bound-services.html

after activity (or fragment) bound service can register self listener , service reports status/progress of operation.

on top of it, if activity disconnects service, service can use command startforeground put notification on device status bar , keep notifying user on operation progress without need of activity

i know way takes lot more code , more complex do. correct way of doing it.


Comments