I'm still learning a few things about scala but I'm wondering if anyone has 
insight on accessing java statics from scala in relation to the Android 
API. This rarely comes up but here's two examples.

>From https://developer.android.com/training/scheduling/wakelock.html

The support library has a WakefulBroadcastReceiver that contains two static 
methods. If i create a scala class that extends this, I can't access the 
static methods for starting a wakeful service and finishing it.

Likewise, 
http://developer.android.com/reference/android/os/PowerManager.WakeLock.html 
I can't declare a WakeLock type with something like `val wakeLock: WakeLock 
= null`.

I have an intent service and worked around this with the following that I 
access in onCreate and onDestroy (letting the type be inferred)

  lazy val (wakeLock, wifiLock) = {
    val pm = 
getSystemService(Context.POWER_SERVICE).asInstanceOf[PowerManager]
    val wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, 
"ClientWakeLock")
    wakeLock.acquire()
    val wm = 
getSystemService(Context.WIFI_SERVICE).asInstanceOf[WifiManager]
    val wifiLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL, 
"ClientWifiLock")
    wifiLock.acquire()
    (wakeLock, wifiLock)
  }

but I'm wondering if there's some other way so that I can declare the type.

-- 
You received this message because you are subscribed to the Google Groups 
"scala-on-android" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to scala-on-android+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to