Android Question using static modul and activity modul

MikeFree

Member
a static modul cannot handle events like HttpJob.
So i created a activity modul.

B4X:
  'test - read all article via Activity-Modul from "Main"  activity modul

    MA_article.strMode = "read_all"
    StartActivity(MA_article)

the code works ... but how to jump back correctly to main modul?

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim strMode As String
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim IME As IME
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    IME.Initialize("IME")
    Log("Starting - MA_article ....")
    'SelectMode
End Sub

Sub Activity_Resume
    SelectMode
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub SelectMode
    Select Case strMode
        Case "read_all"
             Log("INFO - MA_article : calling Article_read_all")
             Article_read_all
             'Activity.Finish
        Case "save"
            'Activity.RemoveAllViews
            'Activity.LoadLayout("Reset")
            'IME.SetLengthFilter(txtUserEmail, 200)
            'txtUserEmail.RequestFocus
    End Select
End Sub

Sub Article_read_all
    'test - read article
    Dim k As HttpJob
    
    k.Initialize("", Me)
    ProgressDialogShow2("Downloading...article",False)
    k.Download(Starter.strURL1 & Starter.strPHP_read_article)
    Wait For (k) JobDone(k As HttpJob)
    If k.Success Then
        Log(k.GetString)
    Else
        Log("Error: " & k.ErrorMessage)
    End If
    ProgressDialogHide
    k.Release
    Activity.Finish
    CallSubDelayed2(Main, "Button1_Click", Me)
End Sub

following log information is displayed ... and then app crashed ... i think the jump back to main activity is wrong.
How can i manage calling a procedure in a activity modul and jump back to main .. the called activity modul should then paused... and the code in main should go on.


** Activity (main) Pause, UserClosed = false **
** Activity (ma_article) Create, isFirst = true **
Starting - MA_article ....
** Activity (ma_article) Resume **
INFO - MA_article : calling Article_read_all
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
** Service (httputils2service) Start **
[{"a_name":"Apfel","a_description":"1","a_quantity":"0","a_createdate":"2017-02-12 06:03:50","a_user":"ADMIN V2"},{"a_name":"Apfel","a_description":"25","a_quantity":"0","a_createdate":"2017-02-12 17:10:42","a_user":"ADMIN V2"},{"a_name":"Apple-new","a_description":"2","a_quantity":"0","a_createdate":"2004-02-20 00:00:00","a_user":"ADMIN V2"},{"a_name":"Apple-new","a_description":"2","a_quantity":"0","a_createdate":"2017-02-04 04:02:33","a_user":"ADMIN V2"},{"a_name":"Apple-new","a_description":"2","a_quantity":"0","a_createdate":"2017-02-04 04:02:33","a_user":"ADMIN V2"},{"a_name":"Bananen","a_description":"2","a_quantity":"0","a_createdate":"2017-02-04 04:02:33","a_user":"ADMIN V2"},{"a_name":"Apple-new","a_description":"2","a_quantity":"0","a_createdate":"2017-02-04 04:02:33","a_user":"ADMIN V2"},{"a_name":"Apple-new","a_description":"2","a_quantity":"0","a_createdate":"2017-02-05 04:02:33","a_user":"ADMIN V2"},{"a_name":"Apple-new","a_description":"2","a_quantity":"0","a_createdate":"2017-02-05 04:02:33","a_user":"ADMIN V2"},{"a_name":"Birnen","a_description":"4","a_quantity":"0","a_createdate":"2017-02-05 05:18:01","a_user":"ADMIN V2"},{"a_name":"Ananas","a_description":"11","a_quantity":"0","a_createdate":"2017-02-12 17:10:42","a_user":"ADMIN V2"},{"a_name":"Mandarinen","a_description":"11","a_quantity":"0","a_createdate":"2017-10-22 19:41:17","a_user":"ADMIN V2"}]
** Activity (ma_article) Pause, UserClosed = true **
sending message to waiting queue (CallSubDelayed - Button1_Click)
running waiting messages (1)
Error occurred on line: 0 (MA_article)
java.lang.Exception: Sub button1_click signature does not match expected signature.
public static void b4a.BitCoin.main_subs_0._button1_click() throws java.lang.Exception

class anywheresoftware.b4a.pc.RemoteObject,
 

MikeFree

Member
thanks Erel ... i tested successfull with new Version B4A 9.9 your Example "ThreePagesExample"...
according to my question above ... i don't whant to use a visible Page ... i want jumping in the activity modul doing httpjob (catching or sending JSON package) an then return to "Mainpage" and continue activity at the point i jumped in the activity modul.

How can i handle the idea using B4X within B4A?
 
Upvote 0
Top