Question

Currently, I am using this in all of my activities:

@Override
public void onRestart(){
    onStart();
    onResume();
    runFadeInAnimation();
}

It "works" but I am clueless if this is going to screw me over in the future. I am unsure if it works by fluke or if this is how it should be done. I tried running it via:

@Override
public void onRestart(){
    super.onRestart();
    runFadeInAnimation();
}

But I can't-- because all of my activities extend my main activity and if I run by super it tries to call my main activities onRestart() which will crash. (I also want my main to fade in, so I am running an animation there too)

How can I handle this gracefully and not unknowingly cause a bug?

Was it helpful?

Solution

Take a look at the Activity Lifecyle here: http://developer.android.com/reference/android/app/Activity.html

What you're doing is actually redundant with what is supposed to automatically happens on an activity restart.

It sounds like you have some possible design issues with how you've defined your main activity and how you're extending it. If I could make a suggestions, I would say that if you have things in an activity that will be common among ALL your activities, put those things in a "parent" activity that you can extend. The way you have your "main" activity defined now seems to have specifics in it that don't lend itself to other activities. So, once you set up your "parent" activity class, extend it to create the "main" activity and put the "fade-in" logic there.

Ultimately, you should be able to call super.onRestart without any detrimental results.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top