Android Question Stuck On Error "An Activity context is Required"

mcqueccu

Well-Known Member
Licensed User
Longtime User
Dear Frens,
I m currently trying to rewrite a custom-view in B4A which contains Grid with pan,zoom(using Gesture Detector lib) for calculating area of geometric figures, structure cut fill etc.
Here i am stuck with an error :
An Activity Context is Required.This call has a process context. Adding a global "Activity object" variable will fix this issue.
I have found a fix from this link :http://www.b4x.com/android/forum/th...s-when-no-activity-context-is-required.19300/
but still i could'nt solve my issue.
I have attached my project here with.
Where :
I have a Model Class Which is used to manage added node in Grid.
Node class for Adding nodes.
But i found an error in Node class for Draw sub method where id1 is a local variable for Node class but it requires the Activity context why?
if i Create a dummy view in Node Class then the error will be solved but it will popup error in my model class in AddNode method, where currnode is local to Model class.

M i doing something wrong?
Please help me if possible.
Best Regards...
 

Attachments

  • DroidViewV1.0.1.zip
    17.6 KB · Views: 198

mcqueccu

Well-Known Member
Licensed User
Longtime User
I haven't checked your code. You can solve the "Activity context is required" error by adding a global UI variable. You don't need to do anything with it:
B4X:
Private DummyButton As Button 'ignore
Dear Erel,
I have studied about this error in forum and got general idea about fixing it.But my current problem is i need to instantiate a Model Class and Node Class, Where the Activity Context Required error poped up.

As defining the Global Variable
B4X:
Private DummyButton AsButton'ignore
1. Error in Node class is solved but cannot instantiate object in Model Class because now it is an activity Object.
2. If i define Dummybutton as global is Model class it will solve the problem in Model Class but Model class couldn't be instantiate from Main activity.

i m struggling for getting solution of this problem.It would be very grateful if u check my code once.
Thanks for ur support.
Best Regards,
 
Upvote 0

mcqueccu

Well-Known Member
Licensed User
Longtime User
It can, but in Globals instead of Process_Globals.
Otherwise it will cause a memory leak.
:confused:
Thank Erel I i have defined:
1.
B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Public objModel As Model
    Private DrawableView1 As DrawableView
End Sub
in main activity.
2. I have Defined Dummy buttons on my Class Model & Node. It solved my Activity context Error.

But
2. Drawableview is a customview which is a Activity object itself how could i access objModel of Main Activity from Drawableview as it is defined as Global variable in Main.
I thought of Defining objmodel in starter services but it also didn't help.

please suggest.
:)
 
Last edited:
Upvote 0

mcqueccu

Well-Known Member
Licensed User
Longtime User
You cannot. UI elements are tied to a specific Activity context. You cannot share them.
Thank u Erel for ur Great Support.
I will think another way to Pass variable(Byval) on DrawableView (Customview) so that i can use the public objModel inside customview.
IS there any method to do such type of task?
 
Upvote 0

mcqueccu

Well-Known Member
Licensed User
Longtime User
Last edited:
Upvote 0
Top