Android Question Can I keep an Activity from restarting? Is this normal Admob/App Life Cycle Behavior?

paris7162

Member
Licensed User
Longtime User
I attached a test app as a zip file. I created a simple test app to show behavior. I used the Admob test ad id so no worries about clicks. First Click the Yellow Star to start animation. Then when I click the ad, and then click the home button while the ad is showing on the screen, the Activity restarts from the beginning. How do I keep the Activity from restarting?

To Show Behavior:
  1. Click the Yellow Star to Start the Animation.
  2. Click the black banner ad at the bottom of the screen.
  3. Click the home button.
  4. Find the App labeled Yellow Star and reOpen it.

The App will start from the very beginning again.

To show normal home button behavior:
  1. Click the Yellow Star to Start the Animation.
  2. Click the home button.
  3. Click the App labeled Yellow Star and reOpen it.
You will see the animation continue in a normal way.

To show(what I think is normal) normal behavior:
  1. Click the Yellow Star to Start the Animation.
  2. Click the black banner ad at the bottom of the screen.
  3. Click the back button.
The animation will continue in a normal way and not restart the activity.

Can I use a Service to keep an Activity in the Foreground? How do I keep the Activity from restarting when I click the home button while an Admob ad is showing?
 

Attachments

  • Test Animation.zip
    34.5 KB · Views: 264

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. Your code can be simplified to about 3 lines:
B4X:
yellow_star.SetLayoutAnimated(10000, 100%x - yellow_star.Width, 100%y - yellow_star.Height, yellow_star.Width, yellow_star.Height)
Sleep(10000)
RunNewSub

2. You are using an Android 2 theme. Better full theme: Full Screen Theme

3. It is a mistake to use Msgbox. Only use non-modal dialogs (MsgboxAsync).

Can I use a Service to keep an Activity in the Foreground?
No.

You should expect the activity to be destroyed and recreated in many cases. If it causes problems then you need to restructure your program.

Relevant tutorial:

 
Upvote 0
Top