Android Question Call other activity when Job process

Irwan Putra

Member
Licensed User
Longtime User
Hello All,
I'm making an application with B4A

This is my flow :
1. Main ---> Process Job
2. in Main, Klik button to call Activity2 (Main activity in processing job....)
3. Activity2 open, but back again to Main activity.
How to handle it?

Thank you very much
 

DonManfred

Expert
Licensed User
Longtime User
Move the jobs to a service (Starter Service for ex.)
 
Upvote 0

Brandsum

Well-Known Member
Licensed User
Than for reply Brandsum,

Yes Http Job. Thanks before
As @DonManfred said, move that job to service and after the job is done send the data back to activity for processing. Like this,
B4X:
Public Sub LoadData() As ResumableSub
    Dim j As HttpJob
    Dim Data() As Byte
    
    j.Initialize("", Me)
    j.Download("URL")
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        Data = j.GetString.GetBytes("UTF8")
        If Not(IsPaused(Main)) Then CallSubDelayed2(Main,"ProcessData",Data)
    End If
    j.Release
    Return j.Success
End Sub
 
Upvote 0

Irwan Putra

Member
Licensed User
Longtime User
As @DonManfred said, move that job to service and after the job is done send the data back to activity for processing. Like this,
B4X:
Public Sub LoadData() As ResumableSub
    Dim j As HttpJob
    Dim Data() As Byte
   
    j.Initialize("", Me)
    j.Download("URL")
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        Data = j.GetString.GetBytes("UTF8")
        If Not(IsPaused(Main)) Then CallSubDelayed2(Main,"ProcessData",Data)
    End If
    j.Release
    Return j.Success
End Sub

Hi, Brandsum
Oke Thank, I will try.
Thank you so much.
 
Upvote 0

Irwan Putra

Member
Licensed User
Longtime User
As @DonManfred said, move that job to service and after the job is done send the data back to activity for processing. Like this,
B4X:
Public Sub LoadData() As ResumableSub
    Dim j As HttpJob
    Dim Data() As Byte
   
    j.Initialize("", Me)
    j.Download("URL")
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        Data = j.GetString.GetBytes("UTF8")
        If Not(IsPaused(Main)) Then CallSubDelayed2(Main,"ProcessData",Data)
    End If
    j.Release
    Return j.Success
End Sub
Hi Brandsum,
I have a question,
How to use variabel to get Data in my Main activity (in sub ProcessData) ?
Sub ProcessData(...)
....
End sub

Can you show me a little example?

Thanks
 
Upvote 0

Brandsum

Well-Known Member
Licensed User
Can you show me a little example?
B4X:
Public Sub ProcessData(data() As Byte) As ResumableSub
    Dim StringData As String = BytesToString(data,0,data.Length,"UTF-8")
    Log(StringData)
End Sub

'if you are downloading json data from httpjob then use this
Public Sub ProcessData(data() As Byte) As ResumableSub
    Dim StringData As String = BytesToString(data,0,data.Length,"UTF-8")
    Dim json As JSONParser
    json.Initialize(StringData)
    Dim OriginalData As List = json.NextArray
    
    Log(OriginalData)
End Sub
 
Upvote 0

Irwan Putra

Member
Licensed User
Longtime User
B4X:
Public Sub ProcessData(data() As Byte) As ResumableSub
    Dim StringData As String = BytesToString(data,0,data.Length,"UTF-8")
    Log(StringData)
End Sub

'if you are downloading json data from httpjob then use this
Public Sub ProcessData(data() As Byte) As ResumableSub
    Dim StringData As String = BytesToString(data,0,data.Length,"UTF-8")
    Dim json As JSONParser
    json.Initialize(StringData)
    Dim OriginalData As List = json.NextArray
   
    Log(OriginalData)
End Sub

Hi Brandsum,
Oke i will try.
Thank you so much.
 
Upvote 0
Top