Iam因此問題持續了4個多小時,iam無法傳遞Service類中sharedPrefernce的更新值。無法接收來自Android服務中的sharedPreference的更新值
public class Background extends Service {
.....
.....
public int onStartCommand(Intent intent, int flags, int startId)
{
return Service.START_STICKY;
}
....
....
private void callService() {
String prefCount=getSharedData("list_update_count");
myb = new myBroad();
Context context = this.getApplicationContext();
myb.SetAlarm(context,prefCount);
}
....
....
public class myListener extends PhoneStateListener
{
@Override
public void onCallStateChanged(int state, String incomingNumber)
{
super.onCallStateChanged(state, incomingNumber);
if (state == TelephonyManager.CALL_STATE_IDLE)
{
String phoneNumber = incomingNumber;
callService();
}
}
}
My BroadcastReceiver ----------------------------------------- -
public class myBroad extends BroadcastReceiver{
.....
.....
.....
public void onReceive(Context context, Intent intent) {
....
.....
}
public void SetAlarm(Context context,String prefCount){
//here the prefCount is not receiving the updated value!!
buildToast(prefCount,context);
}
.....
}
當我在強制停止後啓動應用程序時,正確獲得了來自sharedPreference的更新值。 謝謝...
把你的logcat的信息在這裏 –
我不能看到logcat的O/P .IM任何不熟悉的logcatthat¡ – Shan
的也許是因爲粘貼您的日誌貓這裏解決錯誤 –