1
的Android服務這是我的服務:不叫
public class KeepAliveService extends Service {
Alarm alarm = new Alarm();
public void onCreate()
{
Log.i("","KEEPALIVE onCreate");
super.onCreate();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId)
{
alarm.setAlarm(this);
Log.i("","KEEPALIVE onCreate start command");
return START_STICKY;
}
@Override
public void onStart(Intent intent, int startId)
{
alarm.setAlarm(this);
Log.i("","KEEPALIVE onStart");
}
@Override
public IBinder onBind(Intent intent)
{
return null;
}
}
我有它在我的清單中聲明是這樣,以後我:
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="23" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
<uses-permission android:name="android.permission.READ_LOGS" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />
<application
android:icon="@drawable/ic_launcher"
android:name="com.vidyo.vidyomod.VidyoModApplication"
android:theme="@style/AppTheme"
android:label="@string/app_name"
android:allowBackup="true"
android:supportsRtl="true"
tools:replace="android:icon">
<activity
android:name="com.vidyo.vidyomod.activities.BaseActivity"
android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="vidyocore" />
</intent-filter>
</activity>
<service
android:name="com.vidyo.vidyomod.KeepAliveService"
android:enabled="true"
android:process=":your_service" >
</service>
<receiver android:process=":remote" android:name="com.vidyo.vidyomod.utils.Alarm"></receiver>
<receiver android:name="com.vidyo.vidyomod.utils.AutoStart">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
</intent-filter>
</receiver>
</application>
在我的BaseActivity的onCreate上,我這樣做:
Intent i= new Intent(BaseActivity.this, KeepAliveService.class);
startService(i);
我調試,我在startService斷點停止,但OnCreate不會被調用。爲什麼?
在應用程序內部添加它,但仍然當我調試的onCreate沒有輸入 –
嘗試刪除行android:process =「:your_service」 –
謝謝,現在正在調用onStartComand –