German Notifcation OnGoingEvent wird nicht gelöscht vom Taskmanager

J.Schröder

Member
Licensed User
Wenn mein Service gestartet ist zeige ich eine Notification mit OnGoingEvent=true
Wenn die App vom User aus der Taskliste entfernt wird verschwindet sie nicht...
Gibt es soetwas wie Activity.OnDestroy ?
 

monki

Active Member
Licensed User
Longtime User
Standard Sub's im Starter Service

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Service_Create
    'This is the program entry point.
    'This is a good place to load resources that are not specific to a single activity.

End Sub

Sub Service_Start (StartingIntent As Intent)

End Sub


Sub Service_TaskRemoved
    'This event will be raised when the user removes the app from the recent apps list.
End Sub

'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub

Sub Service_Destroy

End Sub

Sub Service_TaskRemoved

'This event will be raised when the user removes the app from the recent apps list.

End Sub
 

J.Schröder

Member
Licensed User
Hört sich gut an..aber wenn ich
B4X:
Sub Service_TaskRemoved
    'This event will be raised when the user removes the app from the recent apps list.
    notify1.Cancel(2)
End Sub
in den Service eintrage wird die Notification auch nicht gelöscht. ??
 

An Schi

Well-Known Member
Licensed User
Geraten: hast du schn versucht ongoingevent = false zu setzen und dann zu canceln?

Property_501.png
OnGoingEvent As Boolean [write only]

Sets whether this notification is an "ongoing event". The notification will be displayed in the ongoing section
and it will not be cleared.
 

J.Schröder

Member
Licensed User
Vielleicht findet ja jemand anderes die Ursache in meinem TCPIP-Service...
B4X:
#Region  Service Attributes
    #StartAtBoot: False
  
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim ast As AsyncStreamsText
    Dim server As ServerSocket

    Dim Socket1 As Socket 'receive
    Dim AStreams As AsyncStreams 'send
    Dim DEST_IP As String ="192.168.178.29"
    Dim DEST_PORT As Int =51042
    Dim notify1 As Notification
    Dim notify2 As Notification
    Dim Timer1 As Timer
    Dim Received As String=""
    Dim Status As String=""
    Dim socket_connected As Boolean=False
End Sub

Sub Service_Create
    server.Initialize(DEST_PORT, "server")

    Log(server.GetMyWifiIP)
    server.Listen
    Socket1.Initialize("Socket1")
    Socket1.Connect(DEST_IP , DEST_PORT, 5000)
    Timer1.Initialize("Timer1", 5000)
    Timer1.Enabled=False
  
    notify1.Initialize
    notify1.Icon = "icon"
    notify1.Vibrate = False
'    notify1.Vibrate = True
    notify1.Sound = False
'    notify1.Sound = True

    notify2.Initialize
'    notify2.Icon = "icon"
    notify2.Icon = "chip_black_hsm" 'Achtung Icon im Ordner \Objects\res\drawable  UND Schreibgeschützt !!!
    notify2.Vibrate = False
    notify2.Sound = False

End Sub

Sub Timer1_Tick
    ' Try to connect again
    Timer1.Enabled=False
    If socket_connected=False Then
    Socket1.Close
    Socket1.Initialize("Socket1")
    Socket1.Connect(DEST_IP , DEST_PORT, 5000)
    End If
End Sub

Sub Socket1_Connected(Connected As Boolean)As Boolean
    If Connected = True Then
        Timer1.Enabled=False
        'ToastMessageShow("Connected",True)
        AStreams.Initialize(Socket1.InputStream,Socket1.OutputStream,"Astreams")
        SendData2("connected "&DateTime.Date(DateTime.Now) & "-" & DateTime.Time(DateTime.Now))
        SendData2("My IP="&server.GetMyWifiIP)
        socket_connected=True
        notify2.AutoCancel=False  'notify..verschwindet nicht wenn User drauftippt
        notify2.OnGoingEvent=True
        notify2.SetInfo2("H-S-M Service running", DateTime.Date(DateTime.Now) & "-" & DateTime.Time(DateTime.Now),"0", Me)
        notify2.Notify(2)
    Else
'        ToastMessageShow("Server not available",True)
        Status="Server not available"
        socket_connected=False
        notify2.cancel(2)
        Timer1.Enabled=True
    End If
'    btnConnect.Enabled = True
End Sub


Sub SendData2(msg As String)
    Dim Buffer() As Byte
'    Buffer = msg.GetBytes("UTF8")
    Buffer = msg.GetBytes("ISO-8859-1")
    AStreams.Write(Buffer)
End Sub

Sub server_NewConnection (Successful As Boolean, NewSocket As Socket)
    If Successful Then
        If ast.IsInitialized Then ast.Close
        ast.Initialize(Me, "ast", NewSocket.InputStream, NewSocket.OutputStream) 'initialize AsyncStreamsText with the socket streams.
'        notify2.AutoCancel=False  'notify..verschwindet nicht wenn User drauftippt
'        notify2.OnGoingEvent=True
'        notify2.SetInfo2("H-S-M Service running", DateTime.Date(DateTime.Now) & "-" & DateTime.Time(DateTime.Now),"0", Me)
'        notify2.Notify(2)
    Else
'        notify2.cancel(2)
        Log(LastException)
    End If
    server.Listen
End Sub

Sub ast_NewText(Text As String)
    Dim Buffer() As Byte
    Buffer = Text.GetBytes("UTF8")
    Text=BytesToString(Buffer, 0, Buffer.Length, "UTF8")
    Log("Text: " & Text)
    Received=Text 'wird in main über timer_received abgeholt
'    notify1.SetInfo(Text, DateTime.Date(DateTime.Now) & "-" & DateTime.Time(DateTime.Now), Me)
    notify1.AutoCancel=True  'notify..verschwindet wenn User drauftippt
    notify1.SetInfo2(Text, DateTime.Date(DateTime.Now) & "-" & DateTime.Time(DateTime.Now),"0", Main)
        notify1.Notify(1)
End Sub

Sub ast_Terminated
    Log("Connection terminated")
    Timer1.Enabled=True
    socket_connected=False
'    notify2.OnGoingEvent=False
'    notify2.Cancel(2)
End Sub

Sub astreams_disconnected
    Log("Connection terminated")
    Timer1.Enabled=True
    socket_connected=False
End Sub

Sub astreams_error
    Timer1.Enabled=True
    socket_connected=False
End Sub

Sub Service_Start (StartingIntent As Intent)
    Status="Service startet"
End Sub

Sub Service_Destroy
    Socket1.Close
    Status="Service stopped"
    notify2.OnGoingEvent=False
    notify2.Cancel(2)
End Sub

Sub Service_TaskRemoved
    'This event will be raised when the user removes the app from the recent apps list.
    Socket1.Close
    notify1.Cancel(1)
    notify2.OnGoingEvent=False
    notify2.Cancel(2)
End Sub

Würde mich freuen, ich habe m.E. alle Kombinationen und mehrere Android Versionen probiert...
 
Last edited:

monki

Active Member
Licensed User
Longtime User
Hallo,
das funktioniert mit deinem Service.

B4X:
Sub Service_TaskRemoved
    Log("Task entfernt")
    tcpipservice.notify2.Cancel(2)
    'This event will be raised when the user removes the app from the recent apps list.
End Sub

Referenz zum Modul vergessen.

B4X:
Sub Service_TaskRemoved
    'This event will be raised when the user removes the app from the recent apps list.
    notify1.Cancel(2)
End Sub
 

J.Schröder

Member
Licensed User
Ok :)

Habe es vom TCPIP Service in den Starter Service verschoben...das funktioniert.
Nur warum funktioniert es nicht, wenn es im TCPIP Service aufgerufen wird?
Hat der Starter Service andere Bedingungen, wenn ja welche?

Danke den Helfern ;)
 

monki

Active Member
Licensed User
Longtime User
Wenn Du ein Object in einem anderen Modul ansprechen willst, dann musst du die Modulreferenz mit angeben Bsp.
Deinmodulname.notify2.Cancel(2) nicht wie in deinem esten Beispiel nur
notify1.Cancel(2).

monki
 

J.Schröder

Member
Licensed User
Notify1 und 2 werden im Modul TCPIP deklariert deshalb muss/darf ich sie dort nicht zusätzlich referenzieren.
 

monki

Active Member
Licensed User
Longtime User
Das ist durchaus richtig, aber dein vorhaben war/ist die Notification aus dem Starterservice zu Canceln
damit ist die Refrenz auf deinen Service absolut notwendig.

Die Sub "Sub Service_TaskRemoved "wird nur im Starterservice vom System aufgerufen
 

J.Schröder

Member
Licensed User
Die Sub "Sub Service_TaskRemoved "wird nur im Starterservice vom System aufgerufen

Deshalb :):):):) Danke, diese Info hatte ich nirgendwo gefunden
 
Top