我有一個應用程序,對我來說檢測時間更改很重要。到目前爲止,我已經與適當的意圖過濾器接收這樣的:即使應用關閉,如何獲取時間更改廣播
<receiver
android:name=".MyReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.TIME_SET" />
<action android:name="android.intent.action.ACTION_TIME_CHANGED" />
<action android:name="android.intent.action.DATE_CHANGED" />
</intent-filter>
</receiver>
,這是我的接收器:
public class MyReceiver extends BroadcastReceiver {
public MyReceiver() {
}
@Override
public void onReceive(Context context, Intent intent) {
SharedPreferences.Editor spe =PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext()).edit();
spe.putLong("UFCount", 1));
spe.putLong("FCount", 1));
spe.commit();
Toast.makeText(context.getApplicationContext(), "Your job is being done!!", Toast.LENGTH_LONG).show();
}
}
這個接收器只有當應用程序被打開\在最後臺運行。即使應用程序已關閉,我如何使此接收器工作?
您可以點擊此鏈接[http://stackoverflow.com/a/16824692/4049612](http://stackoverflow.com/a/16824692/4049612) – Krishna
@Krishna我不覺得有一個良好的服務始終運行。我不認爲它是這樣做的最佳方式 – hadi