简体   繁体   English

Android 库:是否可以将 Intent 传递到我的库中以检索 ParcelableExtra 的

[英]Android Library: Is it possible to pass an Intent into my Library to retrieve the ParcelableExtra's

I want to use the ParcelableExtra function of an Intent to retrieve an android.nfc.Tag Object我想使用 Intent 的 ParcelableExtra function 来检索 android.nfc.Tag Object

nfcTag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);

In the newIntent function this code works.在 newIntent function 中,此代码有效。 But now I want to write an Android Library which uses the same android.nfc.Tag Object.但现在我想编写一个 Android 库,它使用相同的 android.nfc.Tag Object。

Is it possible and state of the art to pass an Intent into an Android Library?是否有可能和 state 将 Intent 传递到 Android 库中?

It is not "state of the art" to pass an Intent object to a library, while this might be technically possible because because an Intent is just an instance of a standard type Java class that can be passed between methods whether inside the App code or in a library.将 Intent object 传递给库并不是“最先进的”,虽然这在技术上可能是可行的,因为 Intent 只是标准类型 Java ZA2F2ED4F8EBC2CBB4C21A29DC40AB61 内的方法之间传递的一个实例在图书馆。

The reason why you should not uses the Intent Object is because the newer and better NFC API of enableReaderMode does not use Intent s it just gets passed the Tag Java Object directly when a Tag is discovered. The reason why you should not uses the Intent Object is because the newer and better NFC API of enableReaderMode does not use Intent s it just gets passed the Tag Java Object directly when a Tag is discovered.
Thus it is better for your library to accept a Tag object as input as then it could be used with the older and newer (better) NFC API's因此,您的图书馆最好接受Tag object 作为输入,因为它可以与较旧和较新(更好)的 NFC API 一起使用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM