I am trying to display a popup when the application starts (the popup is designed to be an interstitial ad).
I'm using the "Popup" class and i'm setting its content / height / width before displaying it.
The application runs on Windows Phone 8.1 winRT.
I have tried several methods but each time :
But this does not work on real device in Release mode (the popup is not displayed).
This is what i've tried :
1:
InterstitialPopup.IsOpen = true;
2:
DispatcherTimer dt = new DispatcherTimer();
dt.Interval = TimeSpan.FromMilliseconds(100);
dt.Tick += (o, o1) =>
{
dt.Stop();
InterstitialPopup.IsOpen = true;
};
dt.Start();
3:
Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
InterstitialPopup.IsOpen = true;
});
4:
Task.Run(() => InterstitialPopup.IsOpen = true);
5:
Task t = new Task(() => InterstitialPopup.IsOpen = true );
t.RunSynchronously();
And combining those methods.
By placing breakpoints i can see that the code is called, but the popup is never displayed on a real device in Release mode.
By calling myself the popup by clicking on a button, the popup is displayed.
I have tried putting the code in various files (App.xaml.cs, in the ViewModel of my first page, in the xaml.cs of my first page, in a file that initializes some parameters of my app, .....).
Do you have an idea of why this works on emulator-release and device-debug but not on device-release ?
I'm answering myself.
The issue was with the initialization of the popup (please note that i still don't know why this didn't work).
I had this kind of thing :
MyContent c = new MyContent();
c.Attribute1 = "something";
c.Attribute2 = "something";
Popup p = new Popup();
p.Child = c;
And i had to rewrite it like this to make it work on a real device in release mode :
Popup p = new Popup();
p.Child = new MyContent()
{
Attribute1 = "something",
Attribute2 = "something"
};
This way the popup is displayed when the app starts, running on a real device in release mode.