Hi!
I'm having a problem/question:
I want to start an activity from a service-module. The Activity only contains a Label and a button. The user read the text in the Label and confirms it by pressing the button. It works only for 3-4 times. At the 5th time, the activity tries to appear, but the screen appears "empty" (black screen) and the app seems to hang. I have to use the task manager to remove the black screen.
Then I saw in B4A the last sentence from the description to StartActivity: "Note that you should usually not call StartActivity from a Service". Maybe this is the reason... So what is the correct/recommend way to display an activity from a service?
In the thread https://www.b4x.com/android/forum/threads/startactivity-from-service-and-lock-screen.42193/ I found this:
But it didn't help - the same problem.
Details about my project:
I wrote a service module. In Service_Start(), I'm calling a sub, which establishs a TCP-connection (Socket) to my server and this server sends a byte-sequence to my app. I'm using ASyncstreams to read the bytes. In the service-module I have placed the NewData-event (from ASyncStreams). The NewData-event is calling StartActivity(Main). In the Main-Activity, there is a button. If I click on the button, then the following things were done:
After that, there were no instructions to execute, until the Service is called again (after xxx seconds).
I don't understand, why it works for 3-4 times. Maybe a internal memory problem?
During my tests: the phone is not sleeping, the screen is still on and unlocked.
Thank you for any advice.
Nice greetings,
Wolfgang
I'm having a problem/question:
I want to start an activity from a service-module. The Activity only contains a Label and a button. The user read the text in the Label and confirms it by pressing the button. It works only for 3-4 times. At the 5th time, the activity tries to appear, but the screen appears "empty" (black screen) and the app seems to hang. I have to use the task manager to remove the black screen.
Then I saw in B4A the last sentence from the description to StartActivity: "Note that you should usually not call StartActivity from a Service". Maybe this is the reason... So what is the correct/recommend way to display an activity from a service?
In the thread https://www.b4x.com/android/forum/threads/startactivity-from-service-and-lock-screen.42193/ I found this:
B4X:
Dim In As Intent
In.Initialize(In.ACTION_MAIN,"")
In.SetComponent("my.package.name/.main")
In.flags = 6815872 'FLAG_TURN_SCREEN_ON, FLAG_DISMISS_KEYGUARD, FLAG_SHOW_WHEN_LOCKED and FLAG_KEEP_SCREEN_ON
'In.Flags = 33554432 'FLAG_ACTIVITY_FORWARD_RESULT
StartActivity(In)
But it didn't help - the same problem.
Details about my project:
I wrote a service module. In Service_Start(), I'm calling a sub, which establishs a TCP-connection (Socket) to my server and this server sends a byte-sequence to my app. I'm using ASyncstreams to read the bytes. In the service-module I have placed the NewData-event (from ASyncStreams). The NewData-event is calling StartActivity(Main). In the Main-Activity, there is a button. If I click on the button, then the following things were done:
B4X:
StartServiceAt("Starter", DateTime.Now + Global.Service_Intervall*1000, False)
Activity.RemoveAllViews
Activity.Finish
After that, there were no instructions to execute, until the Service is called again (after xxx seconds).
I don't understand, why it works for 3-4 times. Maybe a internal memory problem?
During my tests: the phone is not sleeping, the screen is still on and unlocked.
Thank you for any advice.
Nice greetings,
Wolfgang