Android Question How to start Intent from Service?

Creideiki

Active Member
Licensed User
Longtime User
Hi,

I want to send an email from a service. Normally it should work like this:
B4X:
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
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

Creideiki

Active Member
Licensed User
Longtime User
Create a Activity "launcher" for ex.
Create a sub in this Activity to call the StartActivity.
Call this sub with callsubdelayed from the Service.
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

Expert
Licensed User
Longtime User
That's a dummy Activity, I suppose?
Yes.
Since it is startet, do I have to Activity.Finish it? If yes, where?
Yes.
In the called sub you can do so.
B4X:
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
Top