Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
307 views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...