Clicking on an ad opens a browser, but I cannot go back to the launching activity screen of my Android app

守給你的承諾、 提交于 2019-12-25 03:17:15

问题


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:

  1. 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

  2. By clicking the close (X) button on the screen of your App

  3. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!