Android Question Call a Sub in Activity from a Service

Discussion in 'Android Questions' started by MarkusR, Oct 24, 2018.

Tags:
  1. MarkusR

    MarkusR Well-Known Member Licensed User

    hello,
    i have a little problem, if me call a sub (in an activity) from a service and the activity is not in front
    it seems it create a new activity instead of open the one that is in pause mode.
     
  2. DonManfred

    DonManfred Expert Licensed User

    it is recreated if android has killed it already. Yes.
    If it was still in background then activity_create is called with Firsttime set to false.
     
    Semen Matusovskiy likes this.
  3. MarkusR

    MarkusR Well-Known Member Licensed User

    but if me click back from second activity its there and unchanged.
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Are you calling the sub with CallSubDelayed? It shouldn't recreate the activity.
     
  5. MarkusR

    MarkusR Well-Known Member Licensed User

    i used CallSubDelayed2 from own service
    Code:
    Private Sub Client_MessageArrived(Topic As String, Payload() As Byte)
        
        
    Dim received As String = BytesToString(Payload,0,Payload.Length,"UTF-8")
        
    Dim m As Message
        m.Initialize
        m.Topic = Topic
        m.Body = received
            
        CallSubDelayed2(Main,
    "AddMessage",m)
            
    End Sub
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    The previous activity might be killed. You shouldn't end with two instances of the same activity. Are you sure that this is the case? Have you changed anything special in the manifest editor?
     
  7. MarkusR

    MarkusR Well-Known Member Licensed User

    me expected it used this one, means awake if other activity is in front.

    nothing special in manifest.
    here the log from debug mode, it really killed the previous activity. (this phone is android 5.0.2)
    i switched via menu from main to activitycontrol, there i clicked a button which send data via service to mqtt broker.
    the mqtt broker answer to my connection service and this should show in main activity.
    Manifest Editor
    Code:
    AddManifestText(
    <uses-sdk android:minSdkVersion=
    "21" android:targetSdkVersion="26"/>
    <supports-screens android:largeScreens=
    "true"
        android:normalScreens=
    "true"
        android:smallScreens=
    "true"
        android:anyDensity=
    "true"/>)
    SetApplicationAttribute(android:icon, 
    "@drawable/icon")
    SetApplicationAttribute(android:
    label"$LABEL$")
    CreateResourceFromFile(Macro, Themes.LightTheme)
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    This is fine. It can happen in some cases.
     
  9. MarkusR

    MarkusR Well-Known Member Licensed User

    its unusual because i have only 2 activitis and if me click back from the other one the main always open.
    but i considered to change it that the activity itself fetch this information if needed from service.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice