Android Question [SOLVED] Disappearing widget

Discussion in 'Android Questions' started by noeleon, Jul 23, 2019.

Tags:
  1. noeleon

    noeleon Member Licensed User

    Hi.

    Any idea why my app's 1x1 widget sometimes disappears from the homescreen? It's still there, if you remember where you placed it and long-press then click resize it shows again.

    Panel is 60x60 with 60x60 imageview in it. The image is 512x512 pixels
     
    Last edited: Jul 23, 2019
  2. Erel

    Erel Administrator Staff Member Licensed User

    Can you post your Service_Start code?

    Are you calling rv.UpdateWidget in RequestUpdate event?
     
  3. noeleon

    noeleon Member Licensed User

    The sample project posted here https://www.b4x.com/android/forum/threads/10166
    has an issue in Android 9, there's notification and icon that appears in the status bar so I added
    Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_NEVER
    in Service_Create

    Here's the entire WidgetService
    Code:
    #Region Module Attributes
       
    #StartAtBoot: False
    #End Region

    Sub Process_Globals
       
    Dim rv As RemoteViews
      
    End Sub
    Sub Service_Create
       
    Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_NEVER
       rv = 
    ConfigureHomeWidget("w""rv"0"Wedge it",True)
    End Sub

    Sub Service_Start (StartingIntent As Intent)
       
    If rv.HandleWidgetEvents(StartingIntent) Then Return
       SetImages
    End Sub

    Sub rv_RequestUpdate
       rv.UpdateWidget
    End Sub

    Sub rv_Disabled
       
    Service.StopAutomaticForeground
    End Sub

    Sub Service_Destroy
       
    Service.StopAutomaticForeground
    End Sub

    Sub ImageView1_Click
       State.IsDisabled
       
    If State.isDisabled = True Then
           State.Off(
    False)
           
    ToastMessageShow("Turned ON",False)
       
    Else
           State.Off(
    True)
           
    ToastMessageShow("Turned OFF",False)
       
    End If
       SetImages
    End Sub

    Public Sub SetImages
       State.IsDisabled
       
    If State.isDisabled = True Then
           rv.SetImage(
    "ImageView1"LoadBitmap(File.DirAssets, "off.png"))
       
    Else
           rv.SetImage(
    "ImageView1"LoadBitmap(File.DirAssets, "on.png"))
       
    End If
       rv.UpdateWidget
    End Sub
     
    Last edited: Jul 24, 2019
  4. Erel

    Erel Administrator Staff Member Licensed User

    This code is wrong. You cannot disable automatic foreground mode. It will cause your app to crash.

    You are missing some of the code from the tutorial.
    Code:
    Sleep(0)
        
    Service.StopAutomaticForeground
     
    noeleon likes this.
  5. noeleon

    noeleon Member Licensed User

    Yes my app crashes a lot because of that.

    Can you please update the Widget sample project so that it won't show notification in Android 9?

    20190819053102.mp4_snapshot_00.00.361.jpg
     
    Last edited: Aug 18, 2019
  6. noeleon

    noeleon Member Licensed User

    i declared a notification variable and called notif.cancel
    I think it works.

    EDIT. Not working
     
    Last edited: Aug 19, 2019
  7. noeleon

    noeleon Member Licensed User

    SOLVED.

    I added
    Code:
    sleep(0)
    Service.StopAutomaticForeground
    at the end of most of my subs
     
    Last edited: Aug 19, 2019
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