문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top