Android Question starting new activity in class

ermiakhan

Member
i want to show details for a selected item in a new activity and i simply dont like the way "using public variables and predefined activity"
i prefer to use a class and make activity by calling class.initialize(item_info as some type)
i tried to make an activity in class; after definition of activity "dim a as activity" i got a problem on this line a.initialize("event") error says i should initialize item(activity) before using it( I should initialize that before initializing that o_O)
then i tried to extend class as activity by #Extends: SDKActivities.Activity
b4a says :
error: package SDKActivities does not exist
public class mcn extends SDKActivities.Activity implements BA.SubDelegator{

and for last try i found on forum this topic

adding this line to manifesto :
AddApplicationText(<activity android:name="my.library.package.name.myclassname"/>)

and i got
java.lang.RuntimeException: Object should first be initialized (Activity).
Did you forget to call Activity.LoadLayout?
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
at anywheresoftware.b4a.objects.ViewWrapper.innerInitialize(ViewWrapper.java:73)
at anywheresoftware.b4a.objects.ViewWrapper.Initialize(ViewWrapper.java:67)
at b4a.jf.mcn._initialize(mcn.java:49)
at b4a.jf.main._activity_create(main.java:403)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at b4a.jf.main.afterFirstLayout(main.java:104)
at b4a.jf.main.access$000(main.java:17)
at b4a.jf.main$WaitForLayout.run(main.java:82)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6694)




B4X:
myclass init.

Public Sub Initialize(str As String) As Activity
    Dim a As Activity
    a.Initialize("av")
    Return a
End Sub


and in my main activty i'v

Dim v As myclass
StartActivity(v.Initialize("c"))
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
i want to show details for a selected item in a new activity and i simply dont like the way "using public variables and predefined activity"
i prefer to use a class and make activity by calling class.initialize(item_info as some type)
i tried to make an activity in class; after definition of activity "dim a as activity" i got a problem on this line a.initialize("event") error says i should initialize item(activity) before using it( I should initialize that before initializing that o_O)
then i tried to extend class as activity by #Extends: SDKActivities.Activity
b4a says :
error: package SDKActivities does not exist
public class mcn extends SDKActivities.Activity implements BA.SubDelegator{
All of this will never work. Activities are special OS managed components.

However you don't really need to create an activity. You can use a single activity and switch the layouts as needed.
Two, a bit related ,resources: B4XDialog and B4XPreferencesDialog.
 
Upvote 0

ermiakhan

Member
understood, thanks
but this way i'm worry about memory over load
i tried xui dialog and i found that using a panel on simple customDialog of Dialogs4 lib is very very very simpler but controls i put on this panel on dialog cant trigger event so i have to use dialogs' 3 buttons(cancel,Neg and Pos) and their not beautiful, any idea?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
but this way i'm worry about memory over load
No reason to worry. It has nothing to do with memory usage.

i tried xui dialog and i found that using a panel on simple customDialog of Dialogs4 lib is very very very simpler but controls i put on this panel on dialog cant trigger event so i have to use dialogs' 3 buttons(cancel,Neg and Pos) and their not beautiful, any idea?
As I said you should use B4XDIalog. Very simple to create custom dialogs and everything will work.
 
Upvote 0
Top