Note that there are some explanatory texts on larger screens.

plurals
  1. POUse SubCut (Scala DI) on Android
    primarykey
    data
    text
    <p>I'm writing a game for Android with Scala. Now I'm trying to get the Dick Wall's new Dependency Injection framework SubCut to work on Android.</p> <p>Basically I have a class that extends <code>android.app.Activity</code>, which is the game's only activity and started automatically by Android when the application starts. Now I would need to let this Activity instance be injected by SubCut.</p> <p>Normally you do it like:</p> <pre><code>implicit val bindingModule = ProjectConfiguration val topInstance = new DoStuffOnTheWeb("stuff", new Date()) </code></pre> <p>or</p> <pre><code>val topInstance = new DoStuffOnTheWeb("stuff", new Date())(ProjectConfiguration) </code></pre> <p>but the problem is that the Activity is instantiated by android, not from my code. I tried using something like this:</p> <pre><code>class MyGame()(val bindingModule:BindingModule = MyGameConfigurationModule) extends Activity with Injectable { </code></pre> <p>but apparently android doesn't know how to instantiate this as I now get:</p> <pre><code>ERROR/AndroidRuntime(322): FATAL EXCEPTION: main java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.mycompany.android.mygame..... </code></pre> <p>I was thinking whether it would be possible to "bootstrap" the SubCut somehow in the activity's onCreate() method, as the RoboGuice does with Guice DI framework (it creates an injector instance in that method and passes it <code>this</code> as parameter.</p> <p>Other option I thought about was if I could skip the automatic starting of the Activity and manually start it from <code>android.app.Application</code> with the implicit val required by the Subcut. But somehow this feels like asking for trouble (and yeah, I'm very new to android development).</p> <p>Any ideas?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload