Android Question [Solve] How to wake-up the screen and show message

rraswisak

Active Member
Licensed User
Hi all... i have a sub in activity that execute in sequence sub locate in starter service like this:

B4X:
'Activity
Sub getDataFromServer()
   CallSubDelayed(Starter,"getDataA")
   wait for getDataA_Done (Success As Boolean, Error As String)
   If Success = False Then
       ToastMessageShow(Error,True)
       Return
   End If

   CallSubDelayed(Starter,"getDataB")
   wait for getDataB_Done (Success As Boolean, Error As String)
   If Success = False Then
       ToastMessageShow(Error,True)
       Return
   End If

   CallSubDelayed(Starter,"getDataC")
   wait for getDataC_Done (Success As Boolean, Error As String)
   If Success = False Then
       ToastMessageShow(Error,True)
       Return
   End If

   CallSubDelayed(Starter,"getDataD")
   wait for getDataD_Done (Success As Boolean, Error As String)
   If Success = False Then
       ToastMessageShow(Error,True)
       Return
   End If
End Sub

'Service
Sub getDataC()
   ...
   ...
   CallSubDelayed3(mCallBack, "getDataC_Done", Result, ErrDesc)
End Sub

While processing, the screen goes to sleep (Activity_Pause) and the getDataC_Done is ignored, so what I'm asking for is:

1. While running getDataC sub, there is an error and Success = False, how to wake-up the screen and show the error message
2. If the getDataD is completely finish, how to wake up the screen and show a finish message box to the user

i read @forum (can't remember the link) that i should check at activity_resume sub, but i don't know how to manage.

thank you, any help would be appreciated
 

rraswisak

Active Member
Licensed User
Hi Erel, this is how my app work:

ActService.JPG


I have one activity (main) with lot of classes. In the main activity i load main layout and show menu items. The main layout it self contains header, side menu and a container. Container will be the place for every layout shown base on what menu user choose.

Every menu will represented with a class, the class will do loading layout to the container and do some logic process (read, write to database and do some validation).

There is also dialog class (contain alert, progress and some custom layout dialog) that will be call in the activity, classes or even service to update progress info and completeness.

Since i can't declare variable with activity object in services, so i call service in class (say Class E). For now the service run in background while phone in sleep mode and get all data.

question is:
If i have 5 job in sequence to get data, and there is error in job 3 how i can trap/show the error since the phone in sleep mode so remaining job will be skipped ?
If all 5 job is success, how i can raise a message box and wake-up phone from sleep state

*sorry, maybe this is un-ussual behavior of how app in android work, and far away from standard on how it should be. but this is my style (as newbie), i believe b4a can provide what i plan to build, and it does so far :)
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The code in the activities should only deal with the UI implementation. All other code should be implemented in services or classes that belong to services. Starter service is a good place to hold all the classes.

f i have 5 job in sequence to get data, and there is error in job 3 how i can trap/show the error since the phone in sleep mode so remaining job will be skipped ?
If all 5 job is success, how i can raise a message box and wake-up phone from sleep state
You should start a new thread these questions.
 
Upvote 0

rraswisak

Active Member
Licensed User
You should start a new thread these questions

the question point is same as post #1, just with different/addition explanation.

ok back to topic, i have move the 5 sequential job in class E to Starter service. plus create one new sub (DoAllJob). In class E, i only run;
B4X:
CallSub3(Starter, "DoAllJob", callBack, class_dialog)
Wait For AllJobDone (Success As Boolean, ErrorMsg As String)
. Now everything works fine. When all job done, there is a message box arise.

to wake-up screen, right before message box show up, i add this:
B4X:
starter.ph.Keepalive(true)
ShowMessage
starter.ph.ReleaseKeepAlive

Thank you

*now i'm getting familiar with ResumeableSub, Wait For, CallSubDelayed it's help a lot
 
Upvote 0
Top