Android Question Help: FLAG_IMMUTABLE or FLAG_MUTABLE

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
hi,

i get this error message when running on phone with android 13
on version 9 it works
i set targetsdk to 31
when reduce it to 30 it works on the new phone

my B4A version is 12

searching the forum i found some other posts on that topic and they were referred to use NB6 - here i got lost
i couldn't find any sample that works as all are either partial or used for services which i don't

i don't want to use sdk less than 31 as this is the recommendation now...

anyone can help ?
thanks
 
Solution
Last try - see if attached is working for "31". Have changed the Java code to be as follows:

B4X:
    NFCUtils(final Activity pActivity) {
        mActivity = pActivity;
        mNfcAdapter = NfcAdapter.getDefaultAdapter(mActivity);
        if (Build.VERSION.SDK_INT < 31) {
            mPendingIntent = PendingIntent.getActivity(mActivity, 0,
                    new Intent(mActivity, mActivity.getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
        } else {
       
            mPendingIntent = PendingIntent.getActivity(mActivity, 0,
                    new Intent(mActivity, mActivity.getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 67108864);
        }  
    }

@agraham , please comment if I have it...

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
You don't. You call them from B4X code as 'onPause' and 'onResume'. As I said above Intellisense should show you them to choose when you type the dot after your TapCard variable name.

I've no idea about signatures - I've never used the store.
ok, tried once again to follow your reply
here is the code sample

B4X:
Sub ZeevTest
    onPause
End Sub

and here is the error i get
Undeclared variable 'onpause' is used before it was assigned any value.
I fail to understand the problem. They are methods declared in the library. Intellisense shows them. You just call them as normal.
B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    Dim Card As TapCard
End Sub

Sub Activity_Resume
    Card.onResume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    Card.onPause
End Sub


I don't. I program only for myself and family nowadays.

got it! thanks

now i get a "new" error

this is the code that produces the error (at compile time)

B4X:
Sub Activity_Pause (UserClosed As Boolean)

    'stop reads
    CardReader.onPause

End Sub

the error is also on "onResume"

this is the compiling log with the error

B4A Version: 12.20
Parsing code. (0.01s)
Java Version: 11
Building folders structure. (0.01s)
Running custom action. (0.19s)
Compiling code. (0.02s)

ObfuscatorMap.txt file created in Objects folder.
Compiling layouts code. (0.00s)
Organizing libraries. (0.00s)
(AndroidX SDK)
Compiling resources (0.03s)
Linking resources (0.24s)
Compiling generated Java code. Error
B4A line: 345
CardReader.onPause
src\arkom\nfc\main.java:637: error: onPause() has protected access in tapcardWrapper
mostCurrent._vvvvvvvv7.onPause();
^
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Ah! Johann should have made them public, not protected! They appear in the xml as available but because they are declared protected in the library they are not accessible to B4X code. If he really intended them to be available he needs to modify the library again.
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
Ah! Johann should have made them public, not protected! They appear in the xml as available but because they are declared protected in the library they are not accessible to B4X code. If he really intended them to be available he needs to modify the library again.
oops...
thank you Agraham

now once again - Johan - will you do that?
thanks
 
Upvote 0

Johan Schoeman

Expert
Licensed User
Longtime User
Try with attached library files (jar and xml). Have not tested it but the two methods should now be public (and not protected). The new lib should show as V1.03 in the B4A IDE.
B4X:
    public void onResume() {
        nfcCardReader.enableDispatch();
        
    }
 
    public void onPause() {
        nfcCardReader.disableDispatch();
        
    }
 

Attachments

  • TapCard_V1.03.zip
    128.7 KB · Views: 187
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
Try with attached library files (jar and xml). Have not tested it but the two methods should now be public (and not protected). The new lib should show as V1.03 in the B4A IDE.
B4X:
    public void onResume() {
        nfcCardReader.enableDispatch();
      
    }
 
    public void onPause() {
        nfcCardReader.disableDispatch();
      
    }
thanks

2 issues

1: with the new lib the app crashes with no error message (at runtime)

2: now, when i open the project i get this error when compiling

B4A Version: 12.20
Parsing code. (0.02s)
Java Version: 11
Building folders structure. (0.02s)
Running custom action. (0.18s)
Compiling code. (0.04s)
Compiling layouts code. (0.03s)
Organizing libraries. (0.01s)
(AndroidX SDK)
Compiling resources (0.03s)
Linking resources Error
AndroidManifest.xml:41: error: resource xml/nfc_tech_filter (aka arkom.nfc:xml/nfc_tech_filter) not found.
error: failed processing manifest.

like something was deleted or is missing
this happens even with your original sample app
i took the entire object folder from a previous app and managed to compile it but something went wrong i'm sure
of course my app is dead too...

edit:
found the missing file and replaced it in the right location
now - why is it being deleted ?

i will go back and test the old and new libs
 
Last edited:
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
Try with attached library files (jar and xml). Have not tested it but the two methods should now be public (and not protected). The new lib should show as V1.03 in the B4A IDE.
B4X:
    public void onResume() {
        nfcCardReader.enableDispatch();
       
    }
 
    public void onPause() {
        nfcCardReader.disableDispatch();
       
    }
ok
after testing the new lib i get this runtime error - on both onResume & onPause
maybe something is not initialized?
or maybe it is about where i call the functions?
i call the onResume in activity_resume (tried to move the call to the end of the part where you initialize all elements - didn't help

the onPause i call in activity_pause

when i roll back to lib 1.01 (sdk 31 - the latest you sent) - all works fine


** Activity (main) Resume **
Error occurred on line: 295 (Main)
java.lang.RuntimeException: Object should first be initialized (List).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:67)
at anywheresoftware.b4a.objects.collections.List.Clear(List.java:69)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at arkom.nfc.main.afterFirstLayout(main.java:111)
at arkom.nfc.main.access$000(main.java:17)
at arkom.nfc.main$WaitForLayout.run(main.java:83)
at android.os.Handler.handleCallback(Handler.java:907)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:216)
at android.app.ActivityThread.main(ActivityThread.java:7625)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)
java.lang.Exception: java.lang.RuntimeException: Object should first be initialized (List).
*** Service (httputils2service) Create ***
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
now - why is it being deleted ?
If it's in your Objects/res folder it needs to be made read-only or clean project will delete it.

i get this runtime error - on both onResume & onPause
What is line 295 in your Main activity? It looks like an unitialised List which doesn't seem to correlate with anything in the library.
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
On further examination it looks like it's not within a library call at all. It looks like a B4A List.Clear command in Activity_Resume.
Thanks for the readonly tip...

As per the list - I get this on both pause & resume

So if it is a call location in resume the pause shouldn't fail

I will investigate further tomorrow unless Johan will say something else

Thanks...
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
Btw
I even tried with Johan's original sample so I might (as I did) miss something

Johan is clearing the list before using it...
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
here it is in details

B4X:
    Try
        'tgname.Clear                                                        'clear the list that holds the tag names
        'tg.Clear                                                            'clear the list that holds the tags
        'tglength.clear                                                      'clear the list that holds the tag lengths
        'tgvalue.clear                                                       'clear the list that holds the tag values
  
        'allow reads
        CardReader.onResume 'this is line 301 that generates the error)

    Catch
        Log (LastException.Message)
    End Try

the list clear are johan's code - i remarked them as for the try i don't need them - i read once and quit so no list.clear
it is in activity_resume

here is the log

DeviceID: 4ADBE0CE7317CDCE
** Activity (main) Resume **
Error occurred on line: 301 (Main)
java.lang.NullPointerException: Attempt to invoke virtual method 'void io.github.tapcard.android.NFCCardReader.enableDispatch()' on a null object reference
at tapcardwrapper.tapcardWrapper.onResume(tapcardWrapper.java:98)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at arkom.nfc.main.afterFirstLayout(main.java:111)
at arkom.nfc.main.access$000(main.java:17)
at arkom.nfc.main$WaitForLayout.run(main.java:83)
at android.os.Handler.handleCallback(Handler.java:907)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:216)
at android.app.ActivityThread.main(ActivityThread.java:7625)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)


the same happens here

B4X:
Sub Activity_Pause (UserClosed As Boolean)

    'stop reads
    CardReader.onPause

End Sub

this is the declaration of CardReader in globals

B4X:
    'this is to stop & restart the reading so there's no random reads
    Dim CardReader As TapCard

so what am i doing wrong?

edit: tried with initialize and without for cardreader
nothing helped
 
Last edited:
Upvote 0

agraham

Expert
Licensed User
Longtime User
I'm getting a bit fed up with this. The stack trace above is completely different to the one you posted before. The original one was an uninitialized List and the new one is an uninitialized TapCard! My guess is that you are not being very systematic in your fault finding and are commenting stuff out at random to see what happens. That being said I suspect both have a common reason which is most likely that you hav a WaitFor in Activity_Create that is letting Activity_Resume run before you have initialized the Lists and the Tapcard.
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
I'm getting a bit fed up with this. The stack trace above is completely different to the one you posted before. The original one was an uninitialized List and the new one is an uninitialized TapCard! My guess is that you are not being very systematic in your fault finding and are commenting stuff out at random to see what happens. That being said I suspect both have a common reason which is most likely that you hav a WaitFor in Activity_Create that is letting Activity_Resume run before you have initialized the Lists and the Tapcard.
yes!
i do have wait for in activity_create
it is used to check things before i run or i need to abort

if this is the reason i will need to see where can i put this test so it will not interfere
i was sure that wait for waits until complete and then continues...
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
i was sure that wait for waits until complete and then continues.
WaitFor, as has been posted many times, returns from the Sub immediately and the Sub is re-entered at that point when the condition is satisfied. When an Activity is created B4A runs Activity_Create and then Activity_Resume. The return from a WaitFor in Activity_Create immediately runs Activity_Resume. You need to initialise the Lists and TapCard before calling WaitFor if they are referenced in Activity_Resume.
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
WaitFor, as has been posted many times, returns from the Sub immediately and the Sub is re-entered at that point when the condition is satisfied. When an Activity is created B4A runs Activity_Create and then Activity_Resume. The return from a WaitFor in Activity_Create immediately runs Activity_Resume. You need to initialise the Lists and TapCard before calling WaitFor if they are referenced in Activity_Resume.
they are initialized in activity_create but after the wait for
maybe i just need to chage the order - first to initialize then wait for ?
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
removing the wait completely did not help
also the error in onPause happens all the times
so i'm afraid it is not that
 
Upvote 0
Top