Android Question start activity from service not work in all device

syerif

Active Member
Licensed User
Longtime User
Hi i create some project with start activity from service, in my device it work as expected (activity transparent is show panel)but not work for another device (Activity always on background).

B4X:
Sub Service_Start (StartingIntent As Intent)
    'nb6.h
    'If StartingIntent.IsInitialized Then fm.HandleIntent(StartingIntent)
    'If StartingIntent.IsInitialized Then
    StartServiceAt("", DateTime.Now + 5 * DateTime.TicksPerSecond, True) 'schedule the next task to run in 30 seconds.
    Sleep(0)
    CheckNotif
    'End If
    Service.StopAutomaticForeground 'Call this when the background task completes (if there is one)
End Sub
Sub CheckNotif
'POST API
'load JSON return format to string
ReadJSON
End Sub
Sub ReadJSON
        If Sensor1=0 Or Sensor2=0 Or Sensor3=0 Or Sensor3=0 Or Sensor4=0 Or Sensor5=0 Or Sensor6=0 Or Sensor7=0 Or Sensor8=0 Or Sensor9=0 Or Sensor10=0 Or Sensor11=0 Or Sensor11=0 Then
           
            StartActivity(Notif)
        Else if Sensor1>0 Or Sensor2>0 Or Sensor3>0 Or Sensor3=0 Or Sensor4=0 Or Sensor5=0 Or Sensor6=0 Or Sensor7=0 Or Sensor8=0 Or Sensor9=0 Or Sensor10=0 Or Sensor11=0 Or Sensor11=0 Then
            CallSub(Notif,"Button1_Click")
        End If

    Next
End Sub

Please any advice...
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

syerif

Active Member
Licensed User
Longtime User
Upvote 0

syerif

Active Member
Licensed User
Longtime User
i believe this is better than callsub
B4X:
CallSubDelayed
https://www.b4x.com/android/forum/t...etween-activities-and-services.18691/#content

this way looks odd
B4X:
StartServiceAt("",
For callsub routine it is work perfect in mycode. callsub in my code for close activity where was start, it triger by off fire sensor. On fire sensor triger show activity. And my problem my activity run in background in some real device but in my real device as debuger and install app it work perfect.
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
is the type of Sensor1 is float? then its not good to compare with =0
in the worst case write a log into file (enabled by user) and let the user share this data via mail.
 
Upvote 0

syerif

Active Member
Licensed User
Longtime User
Th
Tip: remove all the sensor variables and use an array instead.

Do you have access to the problematic device? Does it always fail to start the activity? Are you sure that StartActivity is called (add Log("starting")) ?
Thanks erel,
it work when main activity is loaded, but it does not when it minimize or clear from list.
 
Upvote 0

syerif

Active Member
Licensed User
Longtime User
is the type of Sensor1 is float? then its not good to compare with =0
in the worst case write a log into file (enabled by user) and let the user share this data via mail.
is the type of Sensor1 is float? then its not good to compare with =0
in the worst case write a log into file (enabled by user) and let the user share this data via mail.
Sensor1 data type is integer like database field data type
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
i am more confused about this part, why should the activity come in front here?
B4X:
        Else if Sensor1>0 Or Sensor2>0 Or Sensor3>0 Or Sensor3=0 Or Sensor4=0 Or Sensor5=0 Or Sensor6=0 Or Sensor7=0 Or Sensor8=0 Or Sensor9=0 Or Sensor10=0 Or Sensor11=0 Or Sensor11=0 Then
            CallSub(Notif,"Button1_Click")
        End If
 
Upvote 0

syerif

Active Member
Licensed User
Longtime User
i am more confused about this part, why should the activity come in front here?
B4X:
        Else if Sensor1>0 Or Sensor2>0 Or Sensor3>0 Or Sensor3=0 Or Sensor4=0 Or Sensor5=0 Or Sensor6=0 Or Sensor7=0 Or Sensor8=0 Or Sensor9=0 Or Sensor10=0 Or Sensor11=0 Or Sensor11=0 Then
            CallSub(Notif,"Button1_Click")
        End If
This part for close activity where opened, code not correctly at all just for test i am use 2 sensor.
 
Upvote 0
Top