0

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

D.J
  • 1,439
  • 1
  • 12
  • 23
sunpeijie
  • 115
  • 1
  • 10
  • Possible duplicate of [Activity did not call finish? (API 23)](https://stackoverflow.com/questions/32169303/activity-did-not-call-finish-api-23) – Sam Mar 11 '19 at 00:20

2 Answers2

4

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.

Bink
  • 1,934
  • 1
  • 25
  • 41
ianhanniballake
  • 191,609
  • 30
  • 470
  • 443
0

You are using API > 21, so you can use the following style on your activity :

Theme.Translucent.NoTitleBar

The trick with "setVisible(true)" is still not needed.

tryp
  • 1,120
  • 20
  • 26