Admob interstitial ad in LibGDX shows banner? - java

I am trying to display an interstitial in LibGDX after the title screen. I implemented the official github code: https://github.com/TheInvader360/tutorial-libgdx-google-ads/commit/0a5ea376d4eb92b8e87c13a03245adb40b53e811
The code is working fine but I think I'm missing something because whenever I call the showOrLoadInterstital() function, it displays a banner. I want to display a full screen ad instead.
In the code I see an adView being initialized with settings for a banner, but the mentioned function showOrLoadInterstital() uses the InterstitialAd, which is correct. As a beginning game developer (but not beginning developer in general), I am not getting the hang of this, especially those two different ad types together.
Could someone tell me what I am missing here? Should showOrLoadInterstital() just not show a full ad when I call it in my Game class?
Thanks.

Related

How do you make an app that displays a logo for a couple of seconds then a text sentence on the screen?

How do you make an app that displays a logo for a couple of seconds then a text sentence on the screen?
I want to make the app in Android Studio in Java, the goal is that once the app is opened, any sort of logo will appear for 5 seconds, then a sentence will appear then that's it.
I already tried to use the already provided code presets by Android Studio but the problem is, I have no idea how do I do the things that I previously mentioned... I really need help on this.
Any help will be very appreciated, thank you :)
You may have these two Activities namely:
SplashScreenActivity
MainActivity
The former has an ImageView to display a logo. The latter has a TextView to display a sentence. You should learn to make these at first.
Once you have those Activities, then learn to use Intent to switch between the former and the latter.

Why does an activity playing a sound disturb the user interface?

I would like to show a notification and play a sound when the user taps onto that notification. It works somehow when I use an activity to play the sound, as I have written in my own answer to this question: How can I create a notification that plays an audio file when being tapped? (in this question and answer there is also the source code showing how I create the notification and how my PlaySoundActivity looks like.
Yet, I have realized, that while the sound is playing, the appearance of my main application changes and it will not be restored without closing the application.
I have created my application from the "Tabbed Activity" project template.
This is how it looks after being started:
And this is how it looks when I have tapped onto the sound notification (the sections are gone):
Can anyone explain why this happens? Is it a wrong approach to play sound using an activity? But it does not work here when I use a service, I hear nothing! How to solve that?
According to the Android developer reference, "almost all activities interact with the user, so the Activity class takes care of creating a window for you in which you can place your UI with setContentView(View)".
I had not done this. Therefore a new window was displayed, but there was no content.
The better solution for playing a sound is to use a PlaySoundService (service!!!) instead of an activity. It contains almost the same code as an activity would do, but the pending intent is created with PendingIntent.getService(...) instead of PendingIntent.getActivity(...). Using the wrong method does not result in an obvious error message, but the service won't work as expected.

App crashing after sleeping

I'm currently following some video tutorials on Android development, and it's gone fine up until the 8th tutorial, we make a splash screen, and after 2 seconds it's supposed to go to the main application. The problem is, after 2 seconds, the screen goes black and the app crashes.
Logcat Output
I followed the tutorial exactly as he did it, the only difference with mine is that I'm developing for 4.2 instead of 2.2.
I'm also using my Galaxy Note 2 instead of an emulator to test.
I did it all as he did, and pressed play, the app opened on my device and the splash screen was there for 2 seconds (i set it to 2000) and then the spinner (which I added) freezes. The screen goes black, and then it crashes and says "Unfortunately, The Basic Series has stopped."
I've tried both sleep(2000) and Thread.sleep(2000).
Code for the AndroidManifest.xml and the main.java are here
If anyone is curious, this is the video I was following.
avoid splash screens except if u really need them to do some preparation operations..
avoid Thread sleep otherwise you will face ANR crashes (use post runnable with delay instead)
avoid reading this hint: What is your activity class name? Menu, menu, MENU or uNeM?
not so good tutorial IMHO
not honorable mention: if u really want to do it in this (btw not recommended way) check video at 8:48 and try to add catch clause and log exception.
If you need to do some initializations , use AsyncTask , or a thread that upon completion will use Activity.runOnUiThread (so that it won't crash when doing UI operations).
If you need to just show the splash screen and close it after some time , use Handler.postDelayed .
In all possible solutions , don't forget to cancel them upon onPause/onDestroy (depending on what you do/need) , so that if the user has left the app (exited or left it in the background) , it won't open up with the new activity when he resumes it (or worse , show it while it has gone to the background) .

Mopub banner ads - better control of loading/unloading

I want to have fine control over a MoPub banner ad which appears over the top of my game app screen at specific times and not at others. My code currently looks like this (simplified):
LinearLayout linearlayout_for_banner = new LinearLayout (this);
mAdView = new MoPubView(this);
linearlayout_for_banner.addView(mAdView);
The linearlayout_for_banner is transparent, so when there is no advert, the user can see all of the game-play screen underneath. Then at a certain precise point I wish an ad to appear. At the moment, the only function I know to call is mAdView.loadAd() which as far as I know begins a process of going to the internet to seek an ad, then if it finds one it will be drawn on the screen. This is very unsatisfactory, because there is often a delay before it appears. So what I would like are functions like scoop_an_advert_but_dont_show_it_yet() and now_show_that_ad_you_scooped_earlier(). Do they exist? Mopub's documentation seems rather inadequate on this.
Try browsing their github wiki: https://github.com/mopub/mopub-client/wiki/CustomEventsAndroid
You want their, "onReceiveAd" method. Check it out, seems like exactly what you need.
There's no problem with preloading ads and not showing them until a specific time. You can use loadAd() for this. Just swap the visibility of the view when you want it to appear.
NOTE: If you do, you should set that particular ad to not "refresh every x seconds" on the mopub site. Otherwise, it will end up as unintentional ad fraud, since the ad will be refreshing itself while invisible(not to mention tank your CTR).
If you have other ads running in the app without this requirement, I'd recommend a separate ad unit for your sometimes-invisible one, so you can still do the refresh on the other one.

Android, where to put my UI updates and my game loop

So I'm new to Android, and have been having some difficulties with understanding threading/Android UI updating and such. I have some code for a simple game engine I made for an AP computer science final project and I have been trying to make it into an Android app. Coming from the java world I'm not used to threading or worrying about how much time or where a calculation is taking place so I've been having some difficulties getting my game playable. After a splash screen and a main menu, I have it set up so an activity named "Play" starts. In this activity I have found that I can initialize my game engine object(which gets passed from class to class), create an object I created to make an AsyncTask("GuiThreader" in the code linked below) but as soon as I throw in some code in "Play" to do anything more than that (like initialize a button, or start the threader helper class) I get an "Activity has Stopped Unexpectedly" error meaning I'm doing something wrong. I've been looking at a lot of the Android example code but its making little sense to me. So I guess with all that background my bigger question is how can I get this code working? More specifically where should I have my loop that checks when the game is over, and how can I update my button colors outside of the "main" threader to keep it from crashing.
Here is my code:
"Play" Activity (with lines of code commented that I was testing with):
http://pastebin.com/K5kFsMvG
"GuiThreader" used to make the game calculations an AsyncTask: http://pastebin.com/306eUYfq
"GUIdriver" used to call a class that updates the button colors: http://pastebin.com/RANZBH38
"ButtonColorUpdate" saves a value for buttons and updates their colors: http://pastebin.com/qN2fw1RC
If you need anything else just comment and I'll put it up. Thanks in advance for any help!
Start by reading this. Then I'd recommend looking at the code from Replica Island. There's a ton you can learn from studying the code of this project. If you want to interact with GUI "stuff" from a separate thread, a Handler (see the API) can be useful for sending messages between the two.

Categories

Resources