Problem after Read / Write NFC Tags: Runtime Error - API cannot be called while activity is paused

Hello, i have a problem after Read / Write my NFC Tags.

Runtime Error
API cannot be called while activity is paused
End Application

It's really annoying.

I scan my NFC Tag and piep-sound comes.
I must select my App for NFC action and then this error.
(EDIT: The Tag is read or writen but the error message is there and its stupid look)

Please can anyone tell me how can i delete this error?

Samsung Galaxy S9 - Android 9

EDIT: History on Google Groups HERE

Have you read and worked through some of the ideas in this thread:

https://groups.google.com/forum/#!topic/mitappinventortest/0GUm_9suC0M

Also, have you confirmed that you can read from and write to your NFC tag with your device, using a suitable NFC app from the Play Store ?

Yes i read this on the old forum.
Unfortunately, my English is not sufficient for the whole thread. :confused:

I try my best what i understand ther but nothing help.
I read some text with activity starter ?

Can i use this to fix this error?

yes. Its work with my app but this error is irritating

I do not mean your AI2 app....
Which app does it work with ?

Read through the link I provided and try some of the ideas there

Which app does it work with ?

I use the
NFC Tools - Pro Edit

This works good. No action selection what say ... "yes this app" ... no error.

I’m not sure what the most current version of your blocks are, but it is possible for TagRead to be executed even if the activity isn’t in the resumed state as it’s triggered from within a BroadcastReceiver. The write mechanism for NFC checks to see if the activity is running and throws the error you see if not (android source).

There are newer APIs to accomplish what the NFC component does that are more robust to the activity lifecycle. It’s possible that we could adapt the component to use those in the future.

1 Like

Yes, this TagRead staying open was indicated by the developer in the link i put up. Is it possible to set read mode to false once the tag is read ?

There are newer APIs to accomplish what the NFC component does that are more robust to the activity lifecycle. It’s possible that we could adapt the component to use those in the future.

That sounds good. I would be very pleased.

Thanks for helping me.

Not that it helps, but Google has deprecated most of the NFC API starting with Android Q. So depending on what you’re trying to do you may want to look for an alternative solution as it may not be around in a few years.

Hi all,
I have the same issue “api cannot be called while activity is paused”. I tried to read everything but did not understand if any solution has been found.

Is there any solution, to remove the error?

  • I tried with the apk and not the live companion: issue is still there
  • ball cup app works without error.
  • with any other apps downloaded from playstore, everything works well, no error.

thank you!

@fabio Are you using Android Q (Android 10).

This means Google no longer supports the NFC API and does not intend to upgrade it. Evan suggests that you find a different solution that using the NFC API.

There is not a solution to “api cannot be called while activity is paused”. There might never be a solution because Google has deprecated the NFC API. In the world of software development, " deprecated " refers to functions or elements that are in the process of being replaced by newer ones. ... so the 'old' methods no longer work Fabio.

Regards,
Stevve

Dear Steve,
thank you for your reply. I think I have somehow, I don’t know exactly how, solved the problem. it does not appear anymore…
i have a new couple of questions, if I am allowed to.
As far as I understood, you told me that nfc api will, in the future, not be anymore available. Does this mean that it will be impossible to read nfc tags in the future with any app (made with app inventor), or it will be necessary to do it in some oher way? I don’t know if I understood correctly.

If there will be another way to read and write nfc tag, which will be this way?

thank you,

Fabio

Sorry, I forgot to tell you that I am not at all an expert of coding and app making, this is my first try ever. I am not probably aware of what is exactly API and if there are alternatives to it when using app inventor.
Thank you, and thank you for your patience :slight_smile:

Google has deprecated many of the NFC API functions used by the NFC component according to MIT. That means that sooner or later parts of the component will not be usable. When? Maybe next month, maybe next year. What happens depends on what Google decides to do and whether MIT will upgrade the NFC tool it provides. Evan says “developers may want to look for an alternative solution as it (the NFC) may not be around in a few years”. He is speculating; he does not know for sure.

Will there be another way to read and write nfc tag? I do not know . You might read these articles.
Evan indicates that some (but perhaps not all) of the capabilities of the NFC component might have issues as Google deprecates the api.

In the meanwhile, enjoy using the tool.