0

目前,我在所有活动中都使用它:

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

它“有效”,但我不知道这是否会在未来把我搞砸。我不确定它是侥幸还是应该这样做。我尝试通过以下方式运行它:

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

但我不能——因为我的所有活动都扩展了我的主要活动,如果我由 super 运行,它会尝试调用我的主要活动 onRestart() ,这将崩溃。(我也希望我的主要淡入,所​​以我也在那里运行动画)

我怎样才能优雅地处理这个问题而不是在不知不觉中导致错误?

4

1 回答 1

0

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.

于 2011-09-11T21:07:12.547 回答