Android 6.0+ 无法恢复 activity ,在 onResume() 完成之前没有调用 finish()

Android 6.0+ Unable to resume activity , did not call finish() prior to onResume() completing

这是我的 activity,没有布局

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
}

@Override
protected void onStart() {
    super.onStart();
}

@Override
protected void onResume() {
    super.onResume();
    if (getIntent().getAction().equals(NfcAdapter.ACTION_NDEF_DISCOVERED)) {
        Parcelable[] rawMsgs = getIntent().getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
        if (rawMsgs != null) {
            NdefMessage[] msgs = new NdefMessage[rawMsgs.length];
            for (int i = 0; i < rawMsgs.length; i++) {
                msgs[i] = (NdefMessage) rawMsgs[i];
            }
            runNFCTagData(msgs[0].getRecords()[0].getPayload());
            startActivity(new Intent(this, AlarmList.class));
        } else {
            Toast.makeText(this, getResources().getString(R.string.nfc_ndef_not_found), Toast.LENGTH_LONG).show();
        }
    }
}  

‖ 运行 它在 android 6.0+ 上它会被破坏,你可以看到 Unable to resume activity ,在 onResume() 完成之前没有调用 finish() ',但是 6.0- 是 OK.I 找到解决方案并且有效,但我不知道为什么?

这是我的解决方案
  @Override protected void onStart() { super.onStart(); setVisible(true); }

当您将 Theme.NoActivity 用作 documented 时,这是一项要求:

Default theme for activities that don't actually display a UI; that is, they finish themselves before being resumed.

根据 this blog post,此行为是 Android 6.0 的新行为。

您正在使用 API > 21,因此您可以在 activity 上使用以下样式:

Theme.Translucent.NoTitleBar

仍然不需要 "setVisible(true)" 的技巧。