needs to copy files
what very little people usually realize about Android is that Activity
and Fragment
is not the place to execute long running operations, such as download stuff from internet or copying files.
Both Activity
and Fragment
are UI elements which can be destroyed, re-created, without much of a warning.
The correct way of dealing with such an issue is to have a Service
to execute the long running operation, the Activity
or Fragment
should start the service and then immediately "bind" to it, executing the usual unbind
and bind
again upon rotation.
You can read here about service and bounds services: http://developer.android.com/guide/components/bound-services.html
After the activity (or fragment) is bound to the Service
then it can register it self as a listener and the service reports back to it the status/progress of the operation.
On top of it, if the activity disconnects from the service, the service can use the command startForeground
to put a notification on the device status bar and keep notifying the user on the operation progress without the need of an activity
I know that way takes a lot more code and is more complex to do. But that is the correct way of doing it.