问题
Even though there is a similar case here:
After click AdMob ads, I cannot return to my Android app by back button
the code proposed didn't solve my case. So I am posting this if there's somebody with fresh ideas to solve this.
I have coded an app for Android. Now I am trying to add ads to this app. I am implementing the ads from Appodeal. When I show an ad type called MREC (which is a square-like banner) on my main activity, if I click on the ad, it will open a tab in the default browser of the device.
The problem arises when I press the square button on the device (the menu that displays the current running apps): it displays the browser and also my own app as active. If I select my app, Android wont let my app come to the forefront, instead it shows the device background or the recently opened browser. It's like the browser has taken over the "identity" of my app.
So, why I cannot return to the activity screen where the ad is located, and from where the click launched a browser tab?
One more thing is that in the sample apps that Appodeal provide, there is no code in onResume, and there isn't any different code from the Appodeal SDK in the manifest, and yet, the app returns correctly to the main activity after coming from the browser tab. I am also trying to implement Admob ads, and the same effect happens as described in this post.
回答1:
Solved! I implemented the advice by the User: AngraX from this page:
How can I do that in Android. Activity -> WebBrowser -> Acrivity, but Press Back not see the WebBrowser
where he recommends to add this to the Main Activity declaration in the Manifest file of your App:
android:allowTaskReparenting="true"
android:launchMode="singleTask"
And it works! After the Smaato ad in my App launches a tab in the default web browser of the device, I am now able to return to my Main Activity, no matter if the returning is done in any of these 3 ways:
By pressing back button the necessary number of times to return to the Main Activity screen, no matter if you press back button from your App or from the browser
By clicking the close (X) button on the screen of your App
By pressing the square button of your Android device (Menu Button), and then choosing your App
来源:https://stackoverflow.com/questions/53424234/clicking-on-an-ad-opens-a-browser-but-i-cannot-go-back-to-the-launching-activit