How to continue app after back is pressed on clicking admob ad? - android

I am making a fitness app. During the rest period of fixed time I am showing ads using AdMob. If a user clicks on the ad then the app opens up browser/playstore. When the user clicks on back the browser/playstore closes and the user comes back to my app. But my app doesn't realize this and remains frozen. The rest period does not reduce. Only on clicking the app, does the app know that it is active. Is there a way to tell the app to continue once back is pressed after an admob ad is clicked?

When your app loses focus everything is paused. Override onResume method in your activity to restart what ever appears to be paused as per their normal behavior or you have explicitly pauses in onPaused method.

Related

Blocking "Back" button to Close Interstitial Ad

I am adding interstitial ads to my android app using AdMob. I am wondering if there is a way to prevent users from closing them via pressing the "back" button (so they'd have to press the "x" button on the ad).
I know that AdMob is loading the ad in another activity, so I can't use my activity's onKeyDown() to do that.
Also, I am not sure if it's considered a good practice and if it's worth doing at all.
Thank you!
Update:
It appears that there is no easy way to override the back button in the ad's activity (since I don't have access to that activity). Thus, I'll give up on it.
However, I still haven't found any evidence that it is against admob or android policy. In most of android games the back button is overridden to turn the pause mode on and off (as opposed to go further back and eventually exit) and everyone seems to be okay with it. Therefore, I am still open to hear about this aspect from the people that actually know the answer.
P.S.: to the people that say that it's such a horrible thing to block the back button:
I agree that this would make it more annoying for users, but the very idea of interstitial ads is pretty annoying to begin with. Despite of that, it is the most commonly used type of ads these days (guess why - it's just more profitable).
Now, most of the time if you use the back button you can close the ad even before it is loaded on the screen (I'm talking about loading of the layout, not loading of the data from the ad provider). But the whole idea of having ads is to show them to people. So, I think it is reasonable to allow users to close the ad only after it is fully loaded to the screen and not before that. And people that are saying otherwise (but at the same time not having anything against the very concept of interstitial ads) are hypocritical.
Check Google/Android policy for overriding the Back button while publishing your app. Obviously they don't like it either as you disable a main feature from user stand-point.
But if you really need to avoid pressing the back button just override onBackPressed(), you can leave this function blanked.
If you subclass the AdMob activity, then you can override its onBackPressed method to do nothing.
This has recently been fixed by Google. If you update to SDK 19.3.0+ the back button will stop working when an interstitial ad is shown. You must now use the close or x button.
implementation 'com.google.android.gms:play-services-ads:19.6.0'
Source:
Can't dismiss Admob Interstitial Ads by pressing Back key button of Android device
Admob Interstitial ad is not closing when user presses back button on android 7,8,9 but works fine on android 10 and 6

Back button on an ad does not bring control back to the android app

When some users click an ad on my app and they are done viewing the ad, and want to come back to the app, if they hit the back button the control goes to the home screen but the app does not crash because they see it running in the background.
I am not overwriting the default behavior of the controls.
What could be causing this or is it the expected behavior ?
This is not expected behaviour.
If they are definitely pressing the back button (and not the home button), then it sounds like the intent that displayed the Play Store has been configured to start the Activity in a new Task. Unfortunately, there isn't anything you can do do about this except raise it with the ad network in question.

Activity restarts after showing the Ad from Admob

I have an app which has an activity-A. I am showing an Interestial Ad from Admob in it. This is achieved using the Google play services. When there is a weak signal, when I clicked the home button in middle of the app, I could see the home screen. Now when I again clicked the app, the app freshly starts (instead of continuing from the place where i left) and when I close the app using the close button which actually calls the finish() statement and closes the app. But after closing the app the app continuous the activity from the first place where i have pressed the home button which Is very strange to me. Kindly help me to resolve this
This is not happening when I have full internet signal / no signal.

Strange behavior after user clicks adMob ad

I have successfully added admob ads to my android app and can view test ads on the emulator and my development phone (Nexus One). When I click on one of the test ads, it opens the web browser or market to that particular page(gmail or whatever). I click the home button to exit, but when I try to start my app again, it takes me back to the market page or browser that came up when clicking the test ad.
I have a feeling it is something in the onLeaveApplication or onPresentScreen methods implemented with AdListener, but I'm lost and the adMob documentation doesn't provide much info on this.
Generally this is the expected behavior for an application. If you click home and then back on your application icon, most applications will jump back to the last activity on the stack. It's certainly possible to kill your application altogether and treat re-entry as a brand new instance of your application, but you probably don't want that either as all user state will be lost unless you explicitly save it, which is even more work.
The AdMob client SDK listener callbacks are all optional for you to implement; there's no expectation that you do anything in particular. They're there as a convenience for you to pause, save, or resume whatever activity you were doing before.
Users are generally used to hitting the back button to go back to your app, not home and then back into the app.

Android: Determine the previously displayed external Activity

In my application, I used a library that displays ads in my app. When a user clicks on the ad, it launches the Browser app, and the onClick events are handled by the library itself.
I also have a placed code in onPause() and onStart() methods that detects whether any of my Activities are sent to background (user pressed Home) or switching between any of my Activities.
So if the app is either freshly opened (no instance is running) or re-opened from background, it will display a dialog box. If the user is only switching from any of my Activites, then the dialog box shouldn't be displayed.
Now the problem is that when the user clicks on an Ad, the Browser app gets loaded and would mean that my App has been sent to background, and so when the user closes the Browser, it will still display the dialog box when it shouldn't.
Is it even possible for my App to determine the previously displayed external Activity (ie. Browser) and not display the dialog box?
Or are there better approaches that I can follow in implementing such setup?
Thanks in advance.
I don't think that there is a way for your Activity to know, which was the previous activity. A simple work-around is to save the time the dialog was displayed and not displayed it again, before some time passes. You can decide on the exact time period based on your application's requirements.
This may be in fact better in some situations. If the user switches from the Browser to your application and it has been some time he has used your application, it will be appropriate to show the dialog again.
you can use onResume() method to specify the behaviour when your activity get back from the background.

Categories

Resources