My mistake, you are correct. And if i need multiple instances in the general sense, a short wrapper in java can workaround the issue.
On Wed, Dec 3, 2014 at 10:59 AM, Samuel Tardieu <s...@rfc1149.net> wrote: > Perry answered for the WakeLock. What would be the problem in calling > static methods of an abstract class? An abstract class prevents you from > creating instances, and you are not trying to do so. > > 2014-12-03 17:38 GMT+01:00 Daniel Skinner <dan...@dasa.cc>: > >> just try it? In intellij, if I type `var wakeLock: WakeLock = null` and >> it prompts to import `android.os.PowerManager.WakeLock` then the import >> statement says "Cannot resolve symbol WakeLock`. If I clean and compile >> from sbt console, I get "value WakeLock is not a member of object >> android.os.PowerManager". >> >> Also, WakefulBroadcastReceiver is an abstract class, so no, I can't >> simply call the static methods on it. >> >> On Wed, Dec 3, 2014 at 10:24 AM, Samuel Tardieu <s...@rfc1149.net> wrote: >> >>> >>> >>> 2014-12-03 17:09 GMT+01:00 Daniel Skinner <dan...@dasa.cc>: >>> >>>> 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. >>>> >>> >>> What do you mean you “can’t access” them? You can imagine Java static >>> methods as being roughly methods in a class companion object. You don’t >>> inherit them, the way you wouldn’t inherit methods from a companion object >>> as they don’t belong to the corresponding class, and they don’t operate on >>> a particular instance. You need to access those methods by calling >>> WakefulBroadcastReceiver.startWakefulService(…). In Java, being able to >>> call them as if they were methods of your class is merely a convenience, >>> they can’t access any of your non-static methods or fields anyway. >>> >>> >>> . >>> >>>> >>>> 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`. >>>> >>> >>> Again, what do you mean by “I can’t declare a WakeLock”? What happens if >>> you do? I don’t see any reason you couldn’t declare one and assign it the >>> null value (although an Option[WakeLock] would probably be best here). >>> >>> >>> >>> >>>> >>>> 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. >>>> >>> >>> What is wrong with the type (WakeLock, WifiLock)? >>> >>> Sam >>> >>> >>> -- >>> 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. >>> >> >> -- >> 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. >> > > -- > 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. > -- 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.