0

私は毎秒更新したいウィジェットを作成しています(カウントダウン/タイマーウィジェットのようなものです)ので、AlarmManagerとブロードキャストレシーバーを使用して、電話を起こしてすべてのバッテリーを使い果たすことなくこれを達成していますが、私はウィジェットを実行すると、LogCat で一定の​​エラー ストリームが発生し続けます。

08-18 18:40:43.368     390-1988/system_process I/ActivityManager: Process com.dysign.livetubecountdown (pid 9784) has died.
08-18 18:40:44.282      390-414/system_process I/ActivityManager: Start proc com.dysign.livetubecountdown for broadcast com.dysign.livetubecountdown/.WidgetAlarmManager: pid=9809 uid=10144 gids={50144, 3003, 1028}
08-18 18:40:44.306    9809-9809/com.dysign.livetubecountdown E/Trace: error opening trace file: No such file or directory (2)

ご覧のとおり、プロセスは停止してから再起動し続けます。これは、電話がスリープ状態とスリープ状態の両方にある場合に発生します。

AlarmManager を開始する方法は次のとおりです (これはウィジェット プロバイダー クラス内にあります)。

@Override
public void onEnabled(Context context) {
    super.onEnabled(context);
    AlarmManager am=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(context, WidgetAlarmManager.class);
    PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0);
    am.setRepeating(AlarmManager.RTC, System.currentTimeMillis() + 1000, 1000 , pi);
}

そして、これはブロードキャスト レシーバーのコードです。

@Override
public void onReceive(Context context, Intent intent) {
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_main);

    DateFormat format = SimpleDateFormat.getTimeInstance(SimpleDateFormat.MEDIUM, Locale.getDefault());
    remoteViews.setTextViewText(R.id.widgetTextView, "TIME = " + format.format(new Date()));

    ComponentName thisWidget = new ComponentName(context, Widget.class);
    AppWidgetManager manager = AppWidgetManager.getInstance(context);
    manager.updateAppWidget(thisWidget, remoteViews);
}

どんな助けでも大歓迎です、ありがとう、SO!

4

1 に答える 1

2

ご覧のとおり、プロセスは停止してから再起動し続けます。これは、電話がスリープ状態とスリープ状態の両方にある場合に発生します。

プロセスが終了して再起動するという点では、まったく驚くべきことではありません。メソッドが返されるonReceive()と、Android は必要に応じていつでもプロセスを終了できます。

「覚醒と睡眠の両方」に関しては、他の何かがデバイスを覚醒させ続けています。定義上、デバイスがスリープ状態の場合、CPU は命令を実行していないため、ログ ステートメントはありません。adb shell dumpsys powerを持っている人を確認するために使用できますWakeLock

于 2013-08-18T18:02:08.420 に答える