Android Question [SOLVED] Disappearing widget

noeleon

Active 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:

noeleon

Active 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
B4X:
#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:
Upvote 0

noeleon

Active 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:
Upvote 0

noeleon

Active Member
Licensed User
i declared a notification variable and called notif.cancel
I think it works.

EDIT. Not working
 
Last edited:
Upvote 0

noeleon

Active Member
Licensed User
SOLVED.

I added
B4X:
sleep(0)
Service.StopAutomaticForeground
at the end of most of my subs
 
Last edited:
Upvote 0
Top