Error - An activity context is required

tunderin

Member
Licensed User
Longtime User
I am writing a widget that contains several activities. Several of the activities use the number dialog from the Dialogs library, so I started writing a class to handle building the number dialog in the form that an activity requires.

I get the compile error shown in the attached png when I try the code but it is unclear to me what error message means for me to do to fix the error.

Any help anybody might offer would be appreciated...


B4X:
'Class module
Sub Class_Globals
   Dim ndResult As Double 'result of entry made 
   Dim ndNum As Double 
   Dim arg1 As String
   
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize

End Sub

Public Sub getNumber() 
   Private icon As Bitmap
   Dim nd As NumberDialog
   
   icon.Initialize(File.DirAssets, "Cat_Eyes_64.png")   
   
   Select arg1
      Case "mileage"
         nd.ShowSign = False
         nd.Number = ndNum
         nd.Digits = 6
         nd.Decimal = 0
         ndResult = nd.Show("Enter current mileage...", "Accept", "Cancel", "Clear", icon) 
         
      Case "gallons"
         nd.ShowSign = False
         nd.Number = ndNum
         nd.Digits = 5
         nd.Decimal = 3
         ndResult = nd.Show( "Enter number of gallons pumped...", "Accept", "Cancel", "Clear", icon)
         
      Case "cost"
         nd.ShowSign = False
         nd.Number = ndNum
         nd.Digits = 5
         nd.Decimal = 2
         ndResult = nd.Show( "Enter amount paid...", "Accept", "Cancel", "Clear", icon)
         
   End Select
   
   Return ndResult
   
End Sub
 

Attachments

  • error.png
    error.png
    35.5 KB · Views: 219
Last edited:

tunderin

Member
Licensed User
Longtime User
Thanks for your reply...

The numDialog class is actually instantiated in one of the activities in the widget - are you saying that your answer still holds true because the activity is part of a widget?
 
Upvote 0

tunderin

Member
Licensed User
Longtime User
Thanks again...

I am able to add an activity to my widget and it seems to work as well as if it were in a non-widget app.

The numberdialog actually works if I build it inside of the activity the widget starts but broke as soon as I tried to move that code into a class.

It may be that I shouldn't be trying to add activities & classes to a widget but I have seen fairly large apps running out of a widget - I just don't know how complete the B4A support for widgets is.
 
Upvote 0
Top