White screen appears after dismissing Admob interstitial ad - windows-phone-8

I am having an issue with the interstitial ads where on dismissing the interstitial ads, a white screen appears for 2-3 seconds, which is non responsive, and only after 2-3 seconds, it disappears and the app becomes visible again.
Platform: WP8
SDK version: GoogleMobileAdsSdkWindowsPhone8-6.5.13
Code snippet is below (I have placed only the required stuff, apologies in advance if it proves to be difficult to work with)
/*
C# implementation of the s3eAdMob extension.
Add win8-specific functionality here.
These functions are called via Shim class from native code.
*/
/*
* NOTE: This file was originally written by the extension builder, but will not
* be overwritten (unless --force is specified) and is intended to be modified.
*/
using System.Windows.Controls;
using Microsoft.Phone.Controls;
using System.Windows.Media;
using System.Windows;
using System.Threading.Tasks;
using GoogleAds;
namespace s3eAdMobManaged
{
public class s3eAdMobManaged
{
private string interstitialAdID = "ca-app-pub-3090050976150818/7861588484";
private InterstitialAd interstitialAd;
public void initAdMob_managed()
{
interstitialAd = new InterstitialAd(interstitialAdID);
interstitialAd.DismissingOverlay += OnInterstitialDismissingOverlay;
AdRequest adRequestInterstitial = new AdRequest();
adRequestInterstitial.ForceTesting = false;
interstitialAd.LoadAd(adRequestInterstitial);
}
public void showAdMobInterstitial_managed()
{
interstitialAd.ShowAd();
}
private void OnInterstitialDismissingOverlay(object sender, AdEventArgs e)
{
loadInterstitialAdAsync();
}
private async void loadInterstitialAdAsync () {
await Task.Run(() => loadInterstitialAd());
}
private void loadInterstitialAd()
{
interstitialAd = new InterstitialAd(interstitialAdID);
interstitialAd.DismissingOverlay += OnInterstitialDismissingOverlay;
AdRequest adRequestInterstitial = new AdRequest();
adRequestInterstitial.ForceTesting = false;
interstitialAd.LoadAd(adRequestInterstitial);
}
}
}
Description of the code:
initAdMob_managed: For initialization. Called by the app on startup. Loads the ad but does not show it.
showAdMobInterstitial_managed: For showing the already loaded ad.
OnInterstitialDismissingOverlay: Callback that gets executed on dismissing the ad. I am using this method to reload the ad data so that it will be available the next time it is to be shown, this task is carried out asynchronously since the data being loaded is not required right away. When need be, showAdMobInterstitial_managed will get called.
Initially, I thought that it could be OnInterstitialDismissingOverlay logic issue. So, I removed this method altogether (removing this method will cause issue in reloading the ad, but the first time execution should be without any issue). Even after the removal, there was no change.
Thanks,
Ashish

I have the same problem, different engine. You appear to be using marmalade?
If you look at the admob interstitial samples for WP8, you see that they have this white version too as soon as you close the ad.
It just doesn't show that long, as the context switch doesn't take so long.
The engine I am currently using also takes a while to switch back from the ad to the game.
I guess you have encountered the same problem?
My tip: test your game in release mode and without a debugger or console attached ... this speeded up the whole process and the white ad now only is visible for like 1 second compared to 4-5 ... maybe that helps.

Related

Can't set config.forceExit in LibGDX (Lwjgl3)

Here is my Desktop Launcher code:
public class DesktopLauncher {
public static void main (String[] arg) {
Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration();
config.setForegroundFPS(60);
config.setTitle("Game10");
config.setWindowedMode(1240, 760);
config.forceExit = false; // ERROR!!!
new Lwjgl3Application(new GdxGame10(), config);
}
}
In new LWJGL3 config.forceExit not working. I can't find any solution so far. Any help is appreciated.
There is no forceExit in config. So presumably you have a master application that runs a child libGDX component and when you end that child component you find that the entire application shuts down, when you want the master application to continue. I guess you are on desktop because Android would be OK. So you must want to avoid a full System.exit
i.e.
Gdx.app.exit()
shuts down everything.
So when you instantiate a libGDX application you instantiate based on the application type, so for me, I use the same as you
final Lwjgl3Application application = new Lwjgl3Application(Services.GAME_CONTROLLER,config);
and the implementation for exit is
#Override
public void exit () {
running = false;
}
This finished the while loop that drives the application i.e. kills the main thread. If you have -other threads- running in the background they keep going.
If on the other hand you were instantiating LwglAWTCanvas then your shutdown would be this.
#Override
public void exit () {
postRunnable(new Runnable() {
#Override
public void run () {
stop();
System.exit(-1);
}
});
}
which would shut down the entire application. Anyway so forceExit being -false- was to stop a full system exit killing all your threads. The forceExit was to "force" the other threads to finish. It doesn't do that anymore so the fact it is now missing should not matter, your background threads should keep going.
In other words, config.forceExit = false; is now the default behaviour for your application type so you don't need it.

GPS running in background when Here Drive+ is running

i have a problem running my wp (8.0) app properly in the background when HERE Drive+ is running in the foreground. my app is a location based app.
i've setup a little demo project to reproduce and isolate and simplify the problem.
I have a GeoLocator, which is checking and displaying the current location in the PositionChanged event to a label, when in foreground. when running in background, it displays a toast every 5 seconds (to show me, that the PositionChanged event is still triggered).
pretty forward stuff, that works.
public MainPage()
{
InitializeComponent();
DataContext = this;
App.LocationWatcher.ReportInterval = 5000;
App.LocationWatcher.DesiredAccuracy = PositionAccuracy.High;
App.LocationWatcher.PositionChanged += LocationWatcherOnPositionChanged;
App.LocationWatcher.StatusChanged += LocationWatcherOnStatusChanged;
}
private void LocationWatcherOnStatusChanged(Geolocator sender, StatusChangedEventArgs args)
{
DisplayToast("Status:", args.Status.ToString());
}
private void LocationWatcherOnPositionChanged(Geolocator sender, PositionChangedEventArgs args)
{
if (!App.IsRunningInBackground)
{
Dispatcher.BeginInvoke(() => {
this.tbkLastUpdatedValue.Text = DateTime.Now.Ticks.ToString();
this.tbkLatitudeValue.Text = args.Position.Coordinate.Latitude.ToString();
this.tbkLongitudeValue.Text = args.Position.Coordinate.Longitude.ToString();
});
}
else
{
DisplayToast("Location:", args.Position.Coordinate.Latitude.ToString());
}
}
So, now the problem: When my app runs in background, it displays it's toasts, when i run any other app (including the normal map, which actually uses gps), but when i run HERE Drive+, my PositionChanged and my StatusChanged events dont get triggered anymore.
there is an app on the marketplace that is capable to run in background when here drive+ is running in foreground, as stated in the marketplace comments (in german only)
any ideas how to solve this or what may cause that problem?
The Windows SDK is no longer. An alternative could be to use the HERE Maps API for Javascript, which supports vector map data rendering.

AdMob interstitial crashes with NullReferenceException in GoogleAds.DLL

I am trying to integrate an interstitial AdMob ad into a Windows Phone 8 MonoGame. It is the newest version of MonoGame (3.2) and the newest version of the AdMob SDK for Windows Phone 8 (6.5.13). Ideally I would like to be able to preload the ad and show it when the player dies.
This first example works, but it calls ShowAd directly in the event handler when the ad was received.
public void LoadAndShowAd()
{
interstitial = new InterstitialAd("xxx");
interstitial.ReceivedAd += OnAdReceived;
AdRequest adRequest = new AdRequest();
adRequest.ForceTesting = true;
interstitial.LoadAd(adRequest);
}
private void OnAdReceived(object sender, AdEventArgs e)
{
interstitial.ShowAd();
}
This slightly modified example does not work. The ad is received and is ready, but the call to ShowAd crashes within the GoogleAds.DLL with a NullReferenceException. As you can see the only difference is that ShowLoadedAd is called at a later point in time when the ad is ready.
public void LoadAd()
{
interstitial = new InterstitialAd("xxx");
interstitial.ReceivedAd += OnAdReceived;
AdRequest adRequest = new AdRequest();
adRequest.ForceTesting = true;
interstitial.LoadAd(adRequest);
}
public void ShowLoadedAd()
{
if (isReady)
interstitial.ShowAd();
}
private void OnAdReceived(object sender, AdEventArgs e)
{
isReady = true;
}
The "interstitial" object itself is not null, the exception happens within the GoogleAds dll as shown in the stack trace below. The exception itself sadly does not give away much:
System.NullReferenceException was unhandled by user code HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=GoogleAds
StackTrace:
at A.c81d6e02e9732689b8a214cc526c72649.c8b6f578dd247fa29b178e585ca8da582()
at A.c81d6e02e9732689b8a214cc526c72649.ce00282f6ceb6d2b777527815c84e2081()
at GoogleAds.InterstitialAd.ShowAd()
at GameName10.GamePage.<Test2>b__1()
InnerException:
The Google Ads example for Windows Phone 8 and interstitial ads actually uses the second approach which causes the exception in my monogame project. So I assumed it could be an issue with these calls being made from the game loop of monogame being in a different thread. I wrapped all the calls to these functions in Dispatcher.BeginInvoke calls to make sure they are called on the UI thread. However this does not change anything, the first example works regardless if it is wrapped in BeginInvoke or not and the second one does not.
Any input in how to solve this issue or integrate an interstitial AdMob ad into MonoGame successfully is appreciated.
Thanks

How to do CreateBindingSet() on Windows Phone?

In the N+1 video #34 (Progress), there was an example of using CreateBindingSet() for the Android version, which is not typical. But the narrator also mentioned briefly that the same can be done on the Windows platform.
As much as I tried, however, I am unable to get a View's property to be bound to its ModelView on the Windows Phone. I always get a NullReferenceException.
The closest I came was the code below, including suggestions from ReSharper. Here's my FirstView.xaml.cs:
using Cirrious.MvvmCross.Binding.BindingContext;
using Whatever.ViewModels;
namespace Whatever {
// inheriting from IMvxBindingContextOwner was suggested by ReSharper also
public partial class FirstView : BaseView, IMvxBindingContextOwner {
public class MyBindableMediaElement
{
private string _theMediaSource = "whatever";
public string TheMediaSource
{
get
{
return _theMediaSource;
}
set
{
_theMediaSource = value;
}
}
}
public FirstView()
{
InitializeComponent();
_mediaElement = new MyBindableMediaElement(this.theMediaElement);
var set = this.CreateBindingSet<FirstView, FirstViewModel>();
// the corresponding view model has a .SongToPlay property with get/set defined
set.Bind(_mediaElement).For(v => v.TheMediaSource).To(vm => vm.SongToPlay);
set.Apply();
}
public IMvxBindingContext BindingContext { get; set; } // this was suggested by ReSharper
}
I get a NullReferenceException in MvxBaseFluentBindingDescription.cs as soon as the view is created. The exact location is below:
protected static string TargetPropertyName(Expression<Func<TTarget, object>> targetPropertyPath)
{
var parser = MvxBindingSingletonCache.Instance.PropertyExpressionParser; // <----- exception here**
var targetPropertyName = parser.Parse(targetPropertyPath).Print();
return targetPropertyName;
}
I have not seen a working example of creating a binding set on a Windows Phone emulator. Has anyone gotten this to work? Thanks.
I can confirm that the narrator said that remark a little too flippantly without actually thinking about how he might do it...
However, with a little effort, you definitely can get the CreateBindingSet to work in Windows if you want to.
Before you start, do consider some alternatives - in particular, I suspect most people will use either Windows DependencyProperty binding or some hand-crafted code-behind with a PropertyChanged event subscription.
If you do want to add CreateBindingSet code to a Windows project then:
Add the Binding and BindingEx assemblies to your Ui project - the easiest way to do this is using nuget to add the BindingEx package.
In your Setup class, override InitializeLastChance and use this opportunity to create a MvxWindowsBindingBuilder instance and to call DoRegistration on that builder. Both these first two steps are covered in the n=35 Tibet binding video - and it's this second step that will initialise the binding framework and help you get past your current 'NullReferenceException' (for the code, see BindMe.Store/Setup.cs)
In your view, you'll need to implement the IMvxBindingContextOwner interface and you'll need to ensure the binding context gets created. You should be able to do this as simply as BindingContext = new MvxBindingContext();
In your view, you'll need to make sure the binding context is given the same DataContext (view model) as the windows DataContext. For a Phone Page, the easiest way to do this is probably just to add BindingContext.DataContext = this.ViewModel; to the end of your phone page's OnNavigatedTo method. Both steps 3 and 4 could go in your BaseView if you intend to use Mvx Binding in other classes too.
With this done, you should be able to use the CreateBindingSet code - although do make sure that all binding is done after the new MvxBindingContext() has been created.
I've not got a windows machine with me right now so I'm afraid this answer code comes untested - please do post again if it does or doesn't work.
I can confirm it works almost perfectly; the only problem is, there are no defaults register, so one has to do the full binding like:
set.Bind(PageText).For(c => c.Text).To(vm => vm.Contents.PageText).OneTime();
to fix this, instead of registering MvxWindowsBindingBuilder, I am registering the following class. Note: I have just created this class, and needs testing.
public class UpdatedMvxWindowsBindingBuilder : MvxWindowsBindingBuilder
{
protected override void FillDefaultBindingNames(IMvxBindingNameRegistry registry)
{
base.FillDefaultBindingNames(registry);
registry.AddOrOverwrite(typeof(Button), "Command");
registry.AddOrOverwrite(typeof(HyperlinkButton), "Command");
//registry.AddOrOverwrite(typeof(UIBarButtonItem), "Clicked");
//registry.AddOrOverwrite(typeof(UISearchBar), "Text");
//registry.AddOrOverwrite(typeof(UITextField), "Text");
registry.AddOrOverwrite(typeof(TextBlock), "Text");
//registry.AddOrOverwrite(typeof(UILabel), "Text");
//registry.AddOrOverwrite(typeof(MvxCollectionViewSource), "ItemsSource");
//registry.AddOrOverwrite(typeof(MvxTableViewSource), "ItemsSource");
//registry.AddOrOverwrite(typeof(MvxImageView), "ImageUrl");
//registry.AddOrOverwrite(typeof(UIImageView), "Image");
//registry.AddOrOverwrite(typeof(UIDatePicker), "Date");
//registry.AddOrOverwrite(typeof(UISlider), "Value");
//registry.AddOrOverwrite(typeof(UISwitch), "On");
//registry.AddOrOverwrite(typeof(UIProgressView), "Progress");
//registry.AddOrOverwrite(typeof(IMvxImageHelper<UIImage>), "ImageUrl");
//registry.AddOrOverwrite(typeof(MvxImageViewLoader), "ImageUrl");
//if (_fillBindingNamesAction != null)
// _fillBindingNamesAction(registry);
}
}
This is a skeleton from Touch binding, and so far I have only updated three controls to test out (Button, HyperButton and TextBlock)

removing mouse events/controls from swing components with glasspane

I have a client-server application and i am using swing in the client side. My swing client has one main window (jframe) and lots of panels, toolbars and menubar in it.
I want to remove all client action/mouse events (or simply grab and do nothing) while client is waiting response from server by means of glasssPane.
Here is the code i wrote:
private final static MouseAdapter mouseAdapter = new MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{
System.out.println("MouseClicked..!");
}
};
private static Cursor WAIT_CURSOR = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
private static Cursor DEFAULT_CURSOR = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
and
public static void startWaitCursor(JComponent comp)
{
MainWindow root = ((MainWindow) comp.getTopLevelAncestor());
root.getGlassPane().setCursor(WAIT_CURSOR);
root.getGlassPane().addMouseListener(mouseAdapter);
root.getGlassPane().setVisible(true);
}
public static void stopWaitCursor(JComponent comp)
{
MainWindow root = ((MainWindow) comp.getTopLevelAncestor());
root.getGlassPane().setCursor(DEFAULT_CURSOR);
root.getGlassPane().setVisible(false);
}
but i am not able to manage the grab mouse events. Changing cursors at the glassPane is working fine but either i am not able to add mouseAdapter or am not able to make glasssPane become to the top level component.
Any idea?
Thanks.
I realized that my code is working but my problem is threading related. My code was something like:
startWaitCursor();
work(); // server request that takes time
stopWaitCursor();
and changed it to:
startWaitCursor();
SwingUtilities.invokeLater(new Runnable() {
poblic void run() {
try
{
work(); // server request
}
finally
{
stopWaitCursor();
}
by doing this modification i could see the settings i made in the startWaitCursor() method while client is waiting response from the server.
But stil there is a small problem. In startWaitCursor() method i desabled key, mouse and focus events for the glass pane but events are still captured by main frame even glassPane is displayed.
addMouseListener(new MouseAdapter() {});
addMouseMotionListener(new MouseMotionAdapter() {});
addKeyListener(this);
setFocusTraversalKeysEnabled(false);
After server response reached to client and stopWaitCursor() method is invoked the events handled in the main frame.
If i disable the main frame of my application while client is waiting than cursor is not being changed to wait_cursor, if i am not disable the main frame then cursor is being changed but the events are queued.
cheers...
After digging swing threads issues couple of days, i finally found the real answer: SwingWorker
Now my final code is something like,
startWaitCursor();
SwingWorker worker = new SwingWorker() {
public Object doInBackground()
{
doWork(); // time consuming server request
return null;
}
public void done()
{
stopWaitCursor();
}
};
worker.execute();
In startWaitCursor() method i set the glasspane visible (with alpha valued background), display a message to warn the user time consuming job is doing, set the cursor to wait_cursor (hourglass) and consume all the key, mouse events. That is it.
And by using SwingWorker my client is actually responsive (it is working as if no server request is made) but since i display the glasspane and consume all key and mouse events it feels like irresponsive.
What a relief.. SwingWorker rocks...
cheers..