有没有办法确定是否在 onResume() 之前调用了 onCreate()

Is there a way to determine whether onCreate() has just been called prior to onResume()

有没有办法确定是否在 onResume() 之前调用了 onCreate()。

我不想在 onCreate() 中为视图初始化等做一些事情,但我不想在 onResume() 中再次做这些事情,我仍然希望每次我都做这些事情简历...

有没有办法在进入当前onResume()之前判断应用程序是否刚刚创建?

没有内置系统调用可以告诉您 onResume() 是因为 activity 被简单暂停而被调用,还是因为 activity 被调用] 完全重新创建。所以你必须自己跟踪它。

onCreate()中设置一个boolean然后在onResume()中签到比较容易:

public class MainActivity extends AppCompatActivity {

    private boolean didCreate;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        ...
        this.didCreate = true;
    }

    @Override
    protected void onResume() {
        ...

        if (didCreate) {
            ...
        } else {
            ...
        }

        this.didCreate = false;
    }
}