Android Question CallSub vs CallSubDelayed

Discussion in 'Android Questions' started by Alberto Michelis, Dec 6, 2018.

  1. Alberto Michelis

    Alberto Michelis Active Member Licensed User

    Hi,
    I have a sub in an Activity that I need to call from other activities.
    This sub involves Sql calls and web dowloads.
    I need to be sure that this Sub is completed before continue.
    Ive tested CallSubdelayed and it is not called when I need and CallSub seams not to work.
    How can I do it?
     
  2. advansis

    advansis Member Licensed User

    (Forgive me Erel if I'm wrong!)o_O
    When you call a sub belonging to an activity, that activity must be the current one...
    If you call a sub by "CallSubDelayed", the activity will be started, if not already;
    if you call it by "CallSub", the activity should be visible, otherwise the sub wil not be called (so it is used for calling activity-subs from services or classes)
    Why not considering moving your sub in a code/module or class/module ?
     
  3. Alberto Michelis

    Alberto Michelis Active Member Licensed User

    Ive tried to move it to a Code Module but, dont recal what I cant do in a Code module, Sql or Http, so I was forced to keep it in an activity.

    I use a service too, if I move it to the service, will I can call it with CallSub?
     
  4. Erel

    Erel Administrator Staff Member Licensed User

  5. Alberto Michelis

    Alberto Michelis Active Member Licensed User

    Ok, how to do it?, Ive never done it, any doc to read?
     
  6. Alberto Michelis

    Alberto Michelis Active Member Licensed User

    Im trying but and having errors.
    I need a SaxParser and a Sql in the class
    If I dim it in globals I get error initializing them in a sub
    How to deal with it?


    Sub Class_Globals
    Dim SQL1 As SQL
    Dim parser As SaxParser
    Dim Params As Map
    End Sub

    'Initializes the object. You can add parameters to this method if needed.
    Public Sub Initialize

    End Sub

    Sub wNtSyncro(pIdApp As Int,pIdw32 As Int)
    parser.Initialize
    SQL1.Initialize(File.DirInternal, "portit.db", True)
    If Main.VersionNivel>0 And Main.NrSerieWindows<>"" And Main.IdCartera<>0 Then
    ProgressDialogShow(cMessage)

    .....

    Calling this method using:
    Dim s as ntsync
    s.wNtSyncro(0,0)

    I get :

    ntsync_wntsyncro (java line: 569)
    java.lang.NullPointerException: Attempt to invoke virtual method 'void anywheresoftware.b4a.objects.SaxParser.Initialize(anywheresoftware.b4a.BA)' on a null object reference
    at armi.portit.ntsync._wntsyncro(ntsync.java:569)
    at armi.portit.mposicion._popupmenu_itemclicked(mposicion.java:2081)
    at armi.portit.mposicion._abpop_itemclicked(mposicion.java:466)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
    at anywheresoftware.b4a.BA$1.run(BA.java:325)
    at android.os.Handler.handleCallback(Handler.java:743)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:150)
    at android.app.ActivityThread.main(ActivityThread.java:5621)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:684)
    java.lang.NullPointerException: Attempt to invoke virtual method 'void anywheresoftware.b4a.objects.SaxParser.Initialize(anywheresoftware.b4a.BA)' on a null object reference
     
  7. Alberto Michelis

    Alberto Michelis Active Member Licensed User

    Including the sql.init and parse.init in the Initialize of the class does it!
    Now I heve other problems posted in a new thread.
    Thanks
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice