我正在嘗試啓動和關閉服務。我的服務是日誌。如何製作服務Android編程
package com.example.textsmslock;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
public class Logs extends Service
{
@Override
public IBinder onBind(Intent arg0){
// TODO Auto-generated method stub
return null;
}
@Override
public void onStart(Intent intent, int startId) {
// TODO Auto-generated method stub
super.onStart(intent, startId);
System.out.println("LOGS STARTED");
Log.d("TAG", "FirstService started");
}
@Override
public void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
}
}
調用它的活動是ConfirmPin。日誌在函數中被調用。
// imports...
// public class...
public void ConfirmingPin()
{
if(pinCorrect)
{
startService(new Intent("com.example.textsmslock.Logs"));
}
}
這裏是我的AndridManifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.textsmslock"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".ConfirmPin"
android:label="@string/title_activity_confirm_pin" >
<intent-filter>
<action android:name="com.example.textsmslock.ConfirmPin" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<service android:name=".Logs"/>
</application>
的logcat的說:
無法啓動服務意向{行動= com.example.textsmslock.Logs}:不找到
有誰知道我爲什麼無法啓動服務意圖?
@rekire我同意你的大部分編輯,但LogCats應格式化的代碼塊不引用秒。報價塊忽略多行LogCats中的換行符,導致堆棧跟蹤_very_難以閱讀。 – Sam
@Sam通常我也這樣做,但不是一個班輪。 – rekire
@rekire爲什麼使用兩個標準?除了我越來越喜歡技術色的LogCat。 :) – Sam