Bug 33158 - Setting MainPage in iOS's DidEnterBackground does not actually set MainPage
Summary: Setting MainPage in iOS's DidEnterBackground does not actually set MainPage
Status: RESOLVED ANSWERED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.5.0
Hardware: PC Mac OS
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-08-17 12:54 UTC by Shane
Modified: 2015-09-16 21:49 UTC (History)
7 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED ANSWERED

Description Shane 2015-08-17 12:54:32 UTC
Reproduction: https://github.com/shanempope/InformationLeakage

Reproduces on iOS 7.1 simulator, and 7.1 and 8.4 devices. May not reliably reproduce on 8.4 simulator.

1) Press the button on the default page. It goest to the secret page.
2) iOS Home button to collapse the app.
3) Re-open app. Notice that the "Secret Page" is visible for a moment and then the default page comes back up.
Comment 1 asimk 2015-08-18 07:31:13 UTC
I have checked this issue with the help of sample app attached in bug description and able to reproduce this issue.
I have checked this issue with iOS 7.1 simulator.

Screencast: http://www.screencast.com/t/dadLuQte
Ide Log: https://gist.github.com/Asimk360/a2cc7020b7a247a55742 
iOS designer Log: https://gist.github.com/Asimk360/18adb91bf2fd0b4d7f3e 

Environment Info:
=== Xamarin Studio ===

Version 5.9.6 (build 5)
Installation UUID: 449f40dd-b3f1-4028-9a6b-cca0d1a2307d
Runtime:
 Mono 4.0.3 ((detached/9253c5a)
 GTK+ 2.24.23 (Raleigh theme)

 Package version: 400040022

=== Apple Developer Tools ===

Xcode 5.1.1 (5085)
Build 5B1008

=== Xamarin.Mac ===

Version: 2.0.2.121 (Enterprise Edition)

=== Xamarin.Android ===

Version: 5.1.4.41 (Enterprise Edition)
Android SDK: /Users/360logicaxamarinmacmini/Library/Developer/Xamarin/android-sdk-mac_x86
 Supported Android versions:
  2.3   (API level 10)
  4.0.3 (API level 15)
  5.0   (API level 21)
Java SDK: /usr
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Xamarin Android Player ===

Not Installed

=== Xamarin.iOS ===

Version: 8.10.5.16 (Enterprise Edition)
Hash: 9b04b4e
Branch: master
Build date: 2015-08-16 03:57:11-0400

=== Build Information ===

Release ID: 509060005
Git revision: cb62759e77800e955a08a3f2f4feeabe9b5bc8af
Build date: 2015-07-30 16:30:30-04
Xamarin addins: c6796e57050161f3689c87a82fdb1c87a28ac633

=== Operating System ===

Mac OS X 10.10.0
Darwin 360LogicasMacmini.local 14.0.0 Darwin Kernel Version 14.0.0
    Fri Sep 19 00:26:44 PDT 2014
    root:xnu-2782.1.97~2/RELEASE_X86_64 x86_64
Comment 2 Shane 2015-09-10 17:23:16 UTC
This app prevents any Xamarin.Form iOS secure app (log out/hide private info on backgrounding app) from being secure. Does anyone at xamarin know a workaround until this gets resolved?
Comment 3 Jason 2015-09-16 17:59:36 UTC
This is not a Xamarin.Forms issue. iOS actually takes a screenshot of your app just before it minimizes it and returns to the home screen. When you tap the app to bring it back to the foreground what you see zooming in is the screenshot it took. It does this because actually resuming your app's process takes some time therefore to make it appear faster to the user they temporarily show the screenshot. This is the behavior you are seeing.

To get the behavior you want try moving your code in the DidEnterBackground method to the OnResignActivation method. DidEnterBackground gets called after iOS has already taken the screenshot while OnResignActivation gets called before the screenshot is taken.
Comment 4 Shane 2015-09-16 18:08:50 UTC
That is not correct.

On resign activation is not the solution. If you use any common bank app where they log out on background it does not logout on resign activation, because that also fires when you look at all the apps in the App Switcher but don't leave your app. 

If I were to replace it on Activation like you are suggesting it would log out every time the person went to the app switcher then immediately selected the app again. Also it would occur every time they accidentally swiped down form the top or bottom. (Which occurs a lot...)

I had this behavior working before, it was broken with a recent update 1.4.Xish. Your answer is not correct and pollutes this bug thread and I hope you will delete it if possible.

Thanks,
shane
Comment 5 Shane 2015-09-16 21:24:19 UTC
This fixes the issue as far as I can tell. I will test it on devices tomorrow to double check.

    public override void DidEnterBackground(UIApplication uiApplication)
    {
        App.Current.MainPage = new DefaultPage();
        UIApplication.SharedApplication.KeyWindow.SnapshotView(true);
        base.DidEnterBackground(uiApplication);
    }

Specifically the SnapshotView(true) call fixes it.
Comment 6 Shane 2015-09-16 21:49:04 UTC
Marking this as fixed because the solution I've posted above doesn't involve Xamarin.