Top Posts
Recent Posts
Tags
Art
Flash lite
Joke
Flash lite 1.1
Safari Extensions
Study
Tips
Gift
radiko
Weird
Utility
Gadget of the year 2011 nominees
ActionScript 3.0
Movie
Regular expression
Gadget
Photo
Comedy
Titanium mobile
Language
Web Apps
Bookmarklet
Gadget of the year 2009 nominees
Radio Program
Translate
Game
iOS
Android
Book
Google Chrome Extensions
JavaScript
Bacon
Apps
Slider
Youtube
Apple
Live
Gadget of the year 2007
Diary
Prototype
Nintendo DS
OS X
Music
Titanium mobile で Android の Service を使う
Titanium mobile で MP3 プレイヤー的なものを作る時、 Android だと特に何もせずに Titanium.Media.AudioPlayer とか Titanium.Media.Sound を使うとバックグラウンドで音がなってたんですが、Activity が殺されたかなにかで新たに Activity が立ち上がった時に、前になっていた音が止められなくなる事がありました。
通常の Android の作法はどんな感じだろう、と思って調べてみるとバックグラウンドのプロセスは Service が受け持って、 Activity はいつ落とされても良いように、あくまでも UI に徹するという事のようです。
KitchenSink を見てみたら Titanium mobile でも Service が使えるみたい。
KitchenSink の service の例
→ android_services.js
→ testservice.js
tiapp.xml に service を設定する
→ Update your tiapp.xml
で、下記の通り試してみた所、意図した通りに動くようになりました。もっと良いやり方があれば @tanusai までお知らせください。