Get App Instance

23 views
Skip to first unread message

Geraldo Moraes

unread,
Jul 17, 2016, 4:52:50 PM7/17/16
to CodenameOne Discussions
Is there any singleton class similar to Display to get App instance ?

Sometimes I need to get the App instance and all my other classes has App instance private passed by constructor.

Is there any ?

MyApp app = (MyApp) CLASS.getInstance().getApplication();

Shai Almog

unread,
Jul 18, 2016, 12:55:14 AM7/18/16
to CodenameOne Discussions
No. If you mean our main class you can just save it statically.
If you mean the Android activity this is only relevant to Android where we do have some native code to allow that.

Geraldo Moraes

unread,
Jul 18, 2016, 8:03:36 AM7/18/16
to CodenameOne Discussions
Thanks for the explanation.

I create inside my class a static instance that is created in init. This works perfetcly.

I am a beginner using codename one and I have some years as software developer. Your software is an excelent idea and congratulations.
Reply all
Reply to author
Forward
0 new messages