Merge pull request #22374 from davidflanagan/bug1039943

Bug 1039943: make gallery exit if it goes to background while scanning o... r=pdahiya(cherry picked from commit 63a273c6d1bfb2b939718c7262a9e45d92ce9a89)
Merge pull request #22435 from davidflanagan/bug1039943-v2.0

Merge pull request #22374 from davidflanagan/bug1039943