问题描述
编辑:更磨练版本的问题,有一个很好的答案,是:
A more honed version of this question, with a good answer, is at: Rather odd behaviour of Log
编辑:在(怪异)解决方案报告如下答案
The (bizarre) solution is reported as an answer below.
我有一个服务作为其运行相当好应用程序的一部分,虽然是我想了解的行为不寻常位。要做到这一点,我一直把Log.d声明,各种方法的类报告的各个点的状态信息。所有这些似乎工作(即报告中的信息),除了那些在服务类。我知道该服务已启动,因为(a)它的东西,(二)实例化线程正在发行Log.d消息。然而,即使在一开始就:
I have a service as part of an application which is running reasonably well, although there is an unusual bit of behaviour which I am trying to understand. To do this, I have been putting Log.d statement in various methods in classes to report state information at various points. All of these seem to be working (ie reporting the information) except those in the Service class. I know that the service is started because (a) it does something and (b) the threads it instantiates are issuing Log.d messages. However, even right at the start:
@Override
public void onCreate() {
super.onCreate();
Log.d("SMS", "onCreate()");
onCreateReal();
}
永远不会出现此日志消息。什么可能我是做错了?
This log message never appears. What might I be doing wrong?
清单如下:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.stuff.myapp"
android:versionCode="1111111"
android:versionName="0.1" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.stuff.myapp.Core"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="MyService"></service>
<receiver android:name="com.stuff.myapp.WidgetInitiator">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
</intent-filter>
<meta-data android:name="android.appwidget.provider" android:resource="@xml/widget_information"/>
</receiver>
<activity android:name="com.stuff.myapp.ConfigWidgetActivity"
android:theme="@android:style/Theme.Translucent">
</activity>
</application>
作为应用程序的一部分,我呼吁每2分钟一个BroadcastReceiver类(在测试)。类是独立(即不是内部的任何其他类的)。它每次它被称为AlarmManager时间Log.d。但只有一些他的日志调用使其logcat中。再次,建议表示欢迎是出于怎么回事。
As part of the app, I am calling a BroadcastReceiver class every 2 minutes (in testing). The class is stand alone (ie not inside any of the other classes). It does a Log.d every time it is called by AlarmManager. But only some of he Log calls make it to logcat. Again, suggestions welcome for what might be going on here.
推荐答案
已经做了不少工作,解决潜在的问题(见Service通过AlarmManager 正在重新创建的),我仍然有这个问题。该服务还没有被记录。没有任何理由,我可以解释,从短信转变TAG为SMservice使工作。我可以提供任何合理的解释以外,似乎要解决的问题。
Having done quite a lot of work resolving the underlying issue (see Service being re-Created by AlarmManager), I still had this problem. The service still wasn't logging. For no reason I can explain, changing TAG from "SMS" to "SMservice" made it work. I can offer no good explanation other than it seemed to solve the problem.
而且,为了节省你问,如果我改变TAG回SMS消息再次消失。
And, to save you asking, if I change TAG back to "SMS" the messages disappear again.
这篇关于日志不工作(或似乎减少一些行)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!