ゼロから始めるAndroid開発【サービス編】

By yosio
このエントリをはてなブックマークに追加このエントリをdel.icio.usに追加このエントリをLivedoor Clipに追加このエントリをYahoo!ブックマークに追加このエントリをFC2ブックマークに追加このエントリをNifty Clipに追加このエントリをPOOKMARK. Airlinesに追加このエントリをBuzzurl(バザール)に追加このエントリをChoixに追加このエントリをnewsingに追加

前回説明したアプリを作成するため、
今回はその中でも中心的存在となる「Service」の作成をしていきます。

Serviceとは、Activityと異なりバックグラウンドで動作できるアプリの形態です。
まずはServiceを登録するだけの簡単なActivityを書いてみます。

SelfStalkerActivity.java:

ボタンを押したら、SelfStalkerServiceが起動されます。

SelfStalkerServiceでやることは、
・GPS情報をDBに登録
・定期実行の為、サービス自身の次回起動を登録する
です。
GPS情報の登録については後回しすることにして、
サービス自身の次回起動設定をしてみます。
定期的に実行する場合、AlarmManagerを使用します。

SelfStalkerSrevice.java:

確認のためにサービスの冒頭で、トースト表示しています。
10秒ごとにトーストが表示されたら正常に動いています。

サービスが起動されたら、スレッドで処理し、アラームをセットして、サービス自身を終了する。
という流れですね。

書いてみれば、ほとんどApiDemosの焼き増しになってしまいました^^;
次回はDBアクセスについて書いていきます。

関連する投稿


  1. [...] ゼロから始めるAndroid開発【サービス編】 | Android Techfirm Lab [...]

  2. clomidhowto より:

    pcos and clomid not working luteal phase defect clomiphene citrate canada

    clomid ovulation works – clomid therapy for men

    vBulletin v3.8.4, Copyright 2000-2011, Jelsoft Enterprises Ltd. Dreher concluded: Marijuana use by pregnant women is a big red herring that prevents us from looking at the impoverished conditions in which women throughout the world have to bear and raise children. These women are looking for the cheapest, most available substance to alleviate their morning sickness and to give them a better sleep at night in order to get the energy to do the work they have to do every day in order to support those children.
    clomid fertility blend men pcos miscarriage clomid

Leave a Reply

Additional comments powered by BackType