Android Question Start open activity from service

Melghost

Member
Licensed User
Longtime User
Hello!

I found several similar threads but not exactly the issue I'm having. My apologies if I'm wrong.

I'm trying to start an activity from a service. It's easy, and it works fine when the activity is closed.
But when the activity is open, and the service starts, the activity closes instead of remaining open. It doesn't happen when the activity I want to open is Main.

This is my (simplified) code:

Main:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout1")
End Sub


Sub Button1_Click
    StartServiceAt(StActSrv,DateTime.Now+10000,False)
End Sub

Sub Button2_Click
    StartActivity(StAct2)
End Sub

The activity I want to open:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout2")
End Sub

The service:
B4X:
Sub Service_Start (StartingIntent As Intent)
    StartActivity(Main)
End Sub


What am I doing wrong?
Thank you very much
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
I'm not sure I understand. The reason being that in the service start you are always requesting the Main Activity to open...
B4X:
Sub Service_Start (StartingIntent As Intent)
    StartActivity(Main)
End Sub
 
Upvote 0

Melghost

Member
Licensed User
Longtime User
¡Sorry!

My Service code:
B4X:
Sub Service_Start (StartingIntent As Intent)
    StartActivity(StAct2)
End Sub

I've done a lot of tests and I finally posted the wrong one! :)
 
Upvote 0

Melghost

Member
Licensed User
Longtime User
Please don't waste your time. I've just found the mistake.

Thanks, RandomCoder. That was my sample's mistake.

My app's mistake was an Activity.Finish into the Activity_Pause.

Sorry. Today I was a little distracted. :(
 
Upvote 0

RandomCoder

Well-Known Member
Licensed User
Longtime User
I was just mid post when I saw your reply. Thanks for the update.
 
Upvote 0
Top