1

EDIT: A more honed version of this question, with a good answer, is at: Rather odd behaviour of Log

EDIT: The (bizarre) solution is reported as an answer below.

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?

The manifest is as follows:

<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>

[EDIT: another observation] 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.

[EDIT: I have corrected the above because the Threads it instantiates report Log calls correctly, but classes it instantiates don't.]

4

2 回答 2

1

在解决了潜在问题(请参阅Service being re-Created by AlarmManager)做了大量工作之后,我仍然遇到了这个问题。该服务仍然没有记录。我无法解释,将 TAG 从“SMS”更改为“SMservice”使其工作。除了似乎可以解决问题之外,我无法提供任何好的解释。

而且,为了节省您的询问,如果我将 TAG 改回“SMS”,则消息会再次消失。

于 2013-03-28T20:19:09.993 回答
0

您应该在 logcat 中使用“tag:SMS”作为过滤器。

于 2013-03-14T12:57:24.603 回答