app is remaining active during incoming calls

Hi Joshua,

AppCampus QA Team has reviewed my game and there’s one issue that I have to correct. It seems that the game doesn’t suspend/pause on incoming voice calls. I haven’t tested it before, but today I checked it and they’re right - the game is running in the background during the voice call, instead of being deactivated.

Should I declare somewhere in C# that I want to deactivate/suspend the app on incoming calls? I thought it’s a default app behaviour.

Let me know, please.

Thanks

Hello Olaf,

Are you talking about when the phone call “obscures” the top half of the screen?

If so, then yeah, I didn’t set up Corona to suspend during that event.  Wasn’t sure if that was appropriate thing to do, but if it’s causing an app rejection, then I’ll change it.  Sorry about that.  I’ll dig into this today.

But that said, you don’t have to wait for that change from me.  You can actually handle it on your end pretty easily via the WP8 “Obscured” event in C#.

   http://msdn.microsoft.com/en-US/library/windows/apps/microsoft.phone.controls.phoneapplicationframe.obscured(v=vs.105).aspx

Your “App” class (under the “App.xaml” file in Visual Studio’s Solution Explorer) provides a static property named “RootFrame” which provides a reference to your app’s PhoneApplicationFrame providing the needed events.  What you can do is add event handlers to the Obscured and Unobscured events and then call fCoronaPanel.Runtime.Suspend() and fCoronaPanel.Runtime.Resume() respectively.

You can also test the above via the Windows Phone 8.0 emulator per the instructions at the bottom of the following webpage.  That said, I can’t get this to work in the 8.1 emulator; only the 8.0 emulator.

   http://msdn.microsoft.com/library/windows/apps/jj206954(v=vs.105).aspx

Thanks for the info. In my case (Lumia 625) the incoming call covers the whole screen but I guess it’s an obscured event as well.

OK, so now I have a lame question: when I added this handler in App.xaml.cs file:

private void OnObscured(Object sender, ObscuredEventArgs e) { fCoronaPanel.Runtime.Suspend(); }

then I get an error saying that “fCoronaPanel” doesn’t exist in the current context. How should I declare it?

Right.  This is because your “fCoronaPanel” member variable is private and belongs to your MainPage class.  So, no other class has access to it.

Your “App.RootFrame” static property is public.  So, I recommend that you set up your Obscured event handler within your MainPage class instead like this…

public partial class MainPage : PhoneApplicationPage { public MainPage() { // \*\*\* Your old constructor code goes here. \*\*\* // Add application event handlers. App.RootFrame.Obscured += OnAppObscured; App.RootFrame.Unobscured += OnAppUnobscured; } private void OnAppObscured(object sender, ObscuredEventArgs e) { fCoronaPanel.Runtime.Suspend(); } private void OnAppUnobscured(object sender, EventArgs e) { fCoronaPanel.Runtime.Resume(); } }

How does the above work for you?

Yep, it works fine now. Thanks for the guide! :slight_smile:

Olaf,

After some testing today, I’ve noticed that there is an issue with the Obscured/Unobscured events.

The Obscured event gets raised when you press the power button to turn off the screen (that’s fine).  When you press the power button again and slide off the screen lock, the Unobscured event gets raised (that’s fine too).  However, if you very slowly slide up the screen lock, what happens is that the Obscured event gets raised again, but an Unobscured event does not get raised when you finish sliding off the screen lock.  It sounds like a bug in Microsoft’s XAML framework that we’ll have to find a way to work-around.

Here’s a quick procedure on how to reproduce this issue:

1) Start up your app.

  1. Press the power button to turn off the screen.  (Suspends your app.)

  2. Press the power button again to show the screen lock.

  3. Very slowly slide the screen lock up to get back to your app.

Result:  The screen is black and your app has not been resumed.

And you can put breakpoints in your Obscured/Unobscured event handlers to see what I’m talking about.

I’m looking into finding a work-around for this today.

Olaf,

I’ve found a work-around.  Try changing your Obscured event handler to this…

private void OnAppObscured(object sender, ObscuredEventArgs e) { if (e.IsLocked == false) { fCoronaPanel.Runtime.Suspend(); } }

The above will only suspend when a dialog or interruption is received.  It won’t explicitly suspend Corona when pressing the power button or when displaying the screen lock (Corona already automatically handles those particular cases).

The only other issue I’ve noticed is that since the XAML framework does not raise an Unobscured event when slowly sliding off the screen lock, a call interruption won’t raise an Obscured event because XAML thinks your app is already obscured.  But that’s really a bug in the XAML framework and it wouldn’t seem fair to reject your app because of this (unless Microsoft can find a work-around).  Anyways, triggering another Unobscured and Obscured events will bring XAML out of that bad state.

OK, this bug happened to me once but I thought that I pressed the power/lock button again accidentally which caused the black screen. Will include the work around in the update. Thanks!

Did this fix make it into the builds?

No.  Because we’re currently not sure if it is appropriate for us to automatically suspend Corona on our end.  Especially since Microsoft makes this optional on the app developer’s end.  That is, the WP8 operating system does not automatically suspend the app and instead raises an event with the app indicating that it is obscured, making it the app developer’s choice on how to handle the event.  Well, at least until the Microsoft’s app reviewers dictates otherwise.  Perhaps Microsoft believes that games should be automatically suspended, but normal/business apps can keep on animating.  Since Corona is used for more than just games, we were thinking it should be up to the app developer to make this decision using the solution posted above… which is the same solution that other native WP8 developers use.

It’s an interesting problem that we’re not sure what the correct solution should be.

Hello Olaf,

Are you talking about when the phone call “obscures” the top half of the screen?

If so, then yeah, I didn’t set up Corona to suspend during that event.  Wasn’t sure if that was appropriate thing to do, but if it’s causing an app rejection, then I’ll change it.  Sorry about that.  I’ll dig into this today.

But that said, you don’t have to wait for that change from me.  You can actually handle it on your end pretty easily via the WP8 “Obscured” event in C#.

   http://msdn.microsoft.com/en-US/library/windows/apps/microsoft.phone.controls.phoneapplicationframe.obscured(v=vs.105).aspx

Your “App” class (under the “App.xaml” file in Visual Studio’s Solution Explorer) provides a static property named “RootFrame” which provides a reference to your app’s PhoneApplicationFrame providing the needed events.  What you can do is add event handlers to the Obscured and Unobscured events and then call fCoronaPanel.Runtime.Suspend() and fCoronaPanel.Runtime.Resume() respectively.

You can also test the above via the Windows Phone 8.0 emulator per the instructions at the bottom of the following webpage.  That said, I can’t get this to work in the 8.1 emulator; only the 8.0 emulator.

   http://msdn.microsoft.com/library/windows/apps/jj206954(v=vs.105).aspx

Thanks for the info. In my case (Lumia 625) the incoming call covers the whole screen but I guess it’s an obscured event as well.

OK, so now I have a lame question: when I added this handler in App.xaml.cs file:

private void OnObscured(Object sender, ObscuredEventArgs e) { fCoronaPanel.Runtime.Suspend(); }

then I get an error saying that “fCoronaPanel” doesn’t exist in the current context. How should I declare it?

Right.  This is because your “fCoronaPanel” member variable is private and belongs to your MainPage class.  So, no other class has access to it.

Your “App.RootFrame” static property is public.  So, I recommend that you set up your Obscured event handler within your MainPage class instead like this…

public partial class MainPage : PhoneApplicationPage { public MainPage() { // \*\*\* Your old constructor code goes here. \*\*\* // Add application event handlers. App.RootFrame.Obscured += OnAppObscured; App.RootFrame.Unobscured += OnAppUnobscured; } private void OnAppObscured(object sender, ObscuredEventArgs e) { fCoronaPanel.Runtime.Suspend(); } private void OnAppUnobscured(object sender, EventArgs e) { fCoronaPanel.Runtime.Resume(); } }

How does the above work for you?

Yep, it works fine now. Thanks for the guide! :slight_smile:

Olaf,

After some testing today, I’ve noticed that there is an issue with the Obscured/Unobscured events.

The Obscured event gets raised when you press the power button to turn off the screen (that’s fine).  When you press the power button again and slide off the screen lock, the Unobscured event gets raised (that’s fine too).  However, if you very slowly slide up the screen lock, what happens is that the Obscured event gets raised again, but an Unobscured event does not get raised when you finish sliding off the screen lock.  It sounds like a bug in Microsoft’s XAML framework that we’ll have to find a way to work-around.

Here’s a quick procedure on how to reproduce this issue:

1) Start up your app.

  1. Press the power button to turn off the screen.  (Suspends your app.)

  2. Press the power button again to show the screen lock.

  3. Very slowly slide the screen lock up to get back to your app.

Result:  The screen is black and your app has not been resumed.

And you can put breakpoints in your Obscured/Unobscured event handlers to see what I’m talking about.

I’m looking into finding a work-around for this today.

Olaf,

I’ve found a work-around.  Try changing your Obscured event handler to this…

private void OnAppObscured(object sender, ObscuredEventArgs e) { if (e.IsLocked == false) { fCoronaPanel.Runtime.Suspend(); } }

The above will only suspend when a dialog or interruption is received.  It won’t explicitly suspend Corona when pressing the power button or when displaying the screen lock (Corona already automatically handles those particular cases).

The only other issue I’ve noticed is that since the XAML framework does not raise an Unobscured event when slowly sliding off the screen lock, a call interruption won’t raise an Obscured event because XAML thinks your app is already obscured.  But that’s really a bug in the XAML framework and it wouldn’t seem fair to reject your app because of this (unless Microsoft can find a work-around).  Anyways, triggering another Unobscured and Obscured events will bring XAML out of that bad state.

OK, this bug happened to me once but I thought that I pressed the power/lock button again accidentally which caused the black screen. Will include the work around in the update. Thanks!

Did this fix make it into the builds?

No.  Because we’re currently not sure if it is appropriate for us to automatically suspend Corona on our end.  Especially since Microsoft makes this optional on the app developer’s end.  That is, the WP8 operating system does not automatically suspend the app and instead raises an event with the app indicating that it is obscured, making it the app developer’s choice on how to handle the event.  Well, at least until the Microsoft’s app reviewers dictates otherwise.  Perhaps Microsoft believes that games should be automatically suspended, but normal/business apps can keep on animating.  Since Corona is used for more than just games, we were thinking it should be up to the app developer to make this decision using the solution posted above… which is the same solution that other native WP8 developers use.

It’s an interesting problem that we’re not sure what the correct solution should be.