ふむ。
100%の確信はないけれど、自動更新失敗の原因の一つである可能性があるものを発見。

Android DevelopersリファレンスのAlarmManagerのページに普通に以下の様な記述が、、、

The Alarm Manager holds a CPU wake lock as long as the alarm receiver’s onReceive() method is executing. This guarantees that the phone will not sleep until you have finished handling the broadcast. Once onReceive() returns, the Alarm Manager releases this wake lock. This means that the phone will in some cases sleep as soon as your onReceive() method completes. If your alarm receiver called Context.startService(), it is possible that the phone will sleep before the requested service is launched. To prevent this, your BroadcastReceiver and Service will need to implement a separate wake lock policy to ensure that the phone continues running until the service becomes available.

簡単に言うと、
AlarmManagerでスリープ中にwakeupされても、onReceive()が終了次第またスリープしちゃうよ。だから、電源確保は各自ヨロシク!
って事らしい。

はい。
完全に見落としてました。

なので、更新掛けようと思ったけど途中で電源落ちて終了ってな事が起きてる予感。

これを回避するにはPowerManagerクラスを使って、電源を確保する事が必要見たい。
↓がそのクラスの説明。
http://developer.android.com/intl/ja/reference/android/os/PowerManager.html

具体的には↓の様に書くらしい。

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, “My Tag”);
wl.acquire();
..screen will stay on during this section..
wl.release();

wl.acquire();でロックして、wl.release();でロック解除するらしい。

これを実装すれば自動更新処理が安定する!。。。はず。

でも、もうひとつ、
PendingIntentの扱いが良く分かって無いんだよな。。。
これも確認しなくちゃ。

Tagged with:  

One Response to 自動更新失敗の原因はこれか?AlarmManager使用時の注意

  1. きb より:

    っg。いlきょ

コメントを残す

メールアドレスが公開されることはありません。