C Creideiki Active Member Licensed User Longtime User Sep 17, 2021 #1 Hi, I want to send an email from a service. Normally it should work like this: B4X: Copy Private Sub sendMail(to as string) dim myEmail as Email myEmail.to.add(to) myEmail.body = "some text" StartActivity(myEmail.GetIntent) end sub But "you should usually not call StartActivity from Service". Here Erel said one should use CallSubDelayed... that would work for one Activities. What's the right way for starting Intents from a Service?
Hi, I want to send an email from a service. Normally it should work like this: B4X: Copy Private Sub sendMail(to as string) dim myEmail as Email myEmail.to.add(to) myEmail.body = "some text" StartActivity(myEmail.GetIntent) end sub But "you should usually not call StartActivity from Service". Here Erel said one should use CallSubDelayed... that would work for one Activities. What's the right way for starting Intents from a Service?
DonManfred Expert Licensed User Longtime User Sep 17, 2021 #2 Create a Activity "launcher" for ex. Create a sub in this Activity to call the StartActivity. Call this sub with callsubdelayed from the Service. Upvote 0
Create a Activity "launcher" for ex. Create a sub in this Activity to call the StartActivity. Call this sub with callsubdelayed from the Service.
C Creideiki Active Member Licensed User Longtime User Sep 17, 2021 #3 DonManfred said: Create a Activity "launcher" for ex. Create a sub in this Activity to call the StartActivity. Call this sub with callsubdelayed from the Service. Click to expand... That's a dummy Activity, I suppose? Since it is startet, do I have to Activity.Finish it? If yes, where? In the called Sub or in Activity_[Create|Start|Resume]? Upvote 0
DonManfred said: Create a Activity "launcher" for ex. Create a sub in this Activity to call the StartActivity. Call this sub with callsubdelayed from the Service. Click to expand... That's a dummy Activity, I suppose? Since it is startet, do I have to Activity.Finish it? If yes, where? In the called Sub or in Activity_[Create|Start|Resume]?
DonManfred Expert Licensed User Longtime User Sep 17, 2021 #4 Creideiki said: That's a dummy Activity, I suppose? Click to expand... Yes. Creideiki said: Since it is startet, do I have to Activity.Finish it? If yes, where? Click to expand... Yes. In the called sub you can do so. B4X: Copy Public Sub sendMail(to as string) dim myEmail as Email myEmail.to.add(to) myEmail.body = "some text" StartActivity(myEmail.GetIntent) Activity.Finish end sub1 Upvote 0
Creideiki said: That's a dummy Activity, I suppose? Click to expand... Yes. Creideiki said: Since it is startet, do I have to Activity.Finish it? If yes, where? Click to expand... Yes. In the called sub you can do so. B4X: Copy Public Sub sendMail(to as string) dim myEmail as Email myEmail.to.add(to) myEmail.body = "some text" StartActivity(myEmail.GetIntent) Activity.Finish end sub1
Erel B4X founder Staff member Licensed User Longtime User Sep 19, 2021 #6 Note that starting from Android 10, services cannot start activities when the app is in the background (it requires a special permission). Upvote 0
Note that starting from Android 10, services cannot start activities when the app is in the background (it requires a special permission).