Search code examples
androidandroid-6.0-marshmallow

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


This my activity,no layout

@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();
        }
    }
}  

  Run it on android 6.0+ and it will be broken, you can see Unable to resume activity , did not call finish() prior to onResume()completing', but 6.0- is OK.I find a solution and it worked, but I don`t know why?

This is my solution
  @Override protected void onStart() { super.onStart(); setVisible(true); }


Solution

  • This is a requirement when you use Theme.NoActivity as documented:

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

    Per this blog post, this behavior is new to Android 6.0.