Android: How to use custom application class?

202 views
Skip to first unread message

aut scr

unread,
Feb 23, 2015, 5:28:05 AM2/23/15
to rubym...@googlegroups.com
i would like to use static context.
i created a class 

class MyApplication < Android::Os::Application
  def onCreate
    super

    SharedContext.context = self
  end

  def onTerminate
    super
  end
end

app.manifest.child('application') do |application|
  application.update('android:name' => 'MyApplication')
end



java.lang.RuntimeException: Unable to instantiate application com.yourcompany.staticcontext.MyApplication: java.lang.ClassNotFoundException: Didn't find class "com.yourcompany.staticcontext.MyApplication" on path: /data/app/com.yourcompany.staticcontext-2.apk



I can't find MyApplication.class/.java in build folder.

Darin Wilson

unread,
Feb 23, 2015, 2:03:48 PM2/23/15
to rubym...@googlegroups.com
Your application class should be a subclass of Android::App::Application, rather than Android::Os::Application:


If that doesn't help, you might also try setting the application class using the RubyMotion App setting, rather than going through the app manifest:

app.application_class = "MyApplication"

Going through the manifest object *should* work, but I've never actually tried it, and I know the app.application_class setting definitely works.

Good luck!
Darin

aut scr

unread,
Feb 23, 2015, 9:36:20 PM2/23/15
to rubym...@googlegroups.com
Thank you!
I changed subclass to Android::App::Application and added application_class.
It works!

for Android::App::Application & manifest cause 

java.lang.UnsatisfiedLinkError: Native method not found: com.yourcompany.staticcontext.MyApplication.onCreate:()V




Darin Wilson於 2015年2月24日星期二 UTC+8上午3時03分48秒寫道:
Reply all
Reply to author
Forward
0 new messages