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

Discussion in 'Android Questions' started by paris7162, Jun 15, 2018.

  1. paris7162

    paris7162 Member Licensed 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?
     

    Attached Files:

  2. Erel

    Erel Administrator Staff Member Licensed User

    1. Your code can be simplified to about 3 lines:
    Code:
    yellow_star.SetLayoutAnimated(10000100%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).

    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:

     
  3. Erel

    Erel Administrator Staff Member Licensed User

    Forgot to write, setting the activity color to white is also a mistake:
    Code:
    Activity.Color = Colors.White
    You should instead use a light theme. This way the other views will automatically look correct.
     
  4. paris7162

    paris7162 Member Licensed User

    Thanks Erel!
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice