2013-08-18 2 views
0

매 초마다 업데이트하려는 위젯을 만들고 있습니다. (카운트 다운/타이머 위젯과 비슷합니다), AlarmManager와 브로드 캐스트 수신기를 사용하여 전화를 깨우거나 사용하지 않고이를 달성합니다 위젯을 실행할 때까지의 모든 배터리,하지만 로그 캣에서 오류의 일정한 흐름을 점점 계속 : 전화가 깨어 둘 때 당신이 볼 수 있듯이지속적으로 다시 시작하는 브로드 캐스트 수신기

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) 

, 프로세스가 죽어가는 다음 다시 시작 계속해서이 문제가 발생합니다 자고.

@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); 
} 

나는 알람 관리기를 (이 위젯 프로 바이더 클래스 내에) 시작입니다 방법은 다음과

입니다 , 매우 고맙습니다!

+0

질문은 프로세스가 계속 죽어가는 이유입니다. 해당 코드에서 일부 디버깅을 수행 했습니까? 죽는 곳은 어디입니까? 방법? 왜 등 ... –

+0

정확히는 디버깅하기가 어렵습니다. 때로는 5 초마다 오류가 발생하고 15 분에 한 번 오류가 발생합니다. –

+0

아마도 스택 트레이스가 더 있습니까? –

답변

1

휴대 전화가 깨어 있거나 잠 들어있을 때 프로세스가 계속 죽어 다시 시작되는 경우가 있습니다.

프로세스가 죽어서 다시 시작된다는 측면에서 볼 때 완전히 놀랍지는 않습니다. onReceive() 메소드가 반환되면 원하는 때에 언제든지 Android를 종료 할 수 있습니다.

"깨어 있고 잠들다"라는 말의 의미에서 다른 것은 장치를 깨우고 있습니다. 정의에 따르면, 장치가 잠 들어있는 경우 CPU는 명령을 실행하지 않으므로 로깅 명령문이 없습니다. adb shell dumpsys power을 사용하면 누가 WakeLock을 가지고 있는지 확인할 수 있습니다.

+0

LogCat의 메시지는 비교적 정상이며 걱정할 필요가 없습니다. –

+0

@ThomasOwers : "LogCat의 메시지는 비교적 정상입니다"- 예. "걱정할 건 없니?" - 그렇게 말하지 않을거야. 'AlarmManager'를 통해 매초 앱 위젯을 업데이트하면 로그 메시지에서 알 수 있듯이 상당한 양의 CPU 및 RAM 변동이 발생하여 배터리가 소모됩니다. – CommonsWare

+0

그래, 그게 유일한 문제지만, 시계 위젯이 어떻게합니까? 모든 튜토리얼/문서 (및 공식 문서)는이 때 AlarmManager를 사용하여 전화기를 깨운다 고 말합니다. –

관련 문제