Is anything treated differently when an app is set to be the default launcher, and the phone is rebooted? I'm having some trouble, mostly with NFC, but in trying to resolve that it's thrown up some similar issues; these issues only occurred on boot, never afterwards.
The NFC Issue: When my app is running, it reads NFC just fine. I set my app to be the default launcher/home and then reboot the phone, which boots directly into my app, but then:
(first hurdle) nfc = NfcAdapter.getDefaultAdapter(this); might return null, but if you put it in a dirty little do-while, then you can get wait until it doesn't.
(second hurdle) nfc.enableForegroundDispatch(...) might throw a null pointer, but not because of 'nfc' being null, as covered above, but thrown by com.android.nfc.ForegroundUtils.isInForeground(...) (from stack trace). Again, you can get around this, being dirty, by sticking it in a try-catch and a do-while, please don't judge me, most of this is proof of concept.
(third hurdle) now that we've got this far, the app will not receive the NFC intents; if the app is closed and relaunched then it works perfectly - these issues only occured on boot->launcher.
I've tried only calling nfc.enableForegroundDispatch on button push, after app has loaded, but get all the same issues on boot. Then I've tried launching into one activity that, on a button push, launches the next activity, which is the one that listens for NFC intents, but get all the same issues on boot.
Then I tried having the app launch and restart itself on creation, with a boolean extra, like 'dont_restart_again' to avoid a restart loop, which works in general, but issues apperar once again when booting into the app: on that first launch into the app, from boot, the boolean extra either isn't written, or isn't read, thus a restart loop. This 'extra' behaviour makes me think that the initial issue with NFC only on boot isn't NFC specific, rather boot into app as default launcher specific.
Hence my question: is there something hugely different between booting into an app, and otherwise launching an app?