2015-06-26 35 views
0

我有下一個要求:如果設備在計算過程中重新啓動,那麼應用程序應該繼續從設備關機點的同一點開始完成啓動計算。所以我想在關閉手機之前保存我的數據。我正在使用廣播接收器。我的broadcastReceiver應該在用戶關機時觸發。爲此我使用關機前如何保存數據?

IntentFilter filter = new IntentFilter(Intent.ACTION_SHUTDOWN); 
BroadcastReceiver receiver = new ShutdownReceiver(); 
registerReceiver(receiver,filter); 

但我不知道如何通過這個過濾器把額外的數據。所以我認爲這將是很好的使用這樣的smt:

shutdownIntent = new Intent(this,ShutdownReceiver.class); 
    shutdownIntent.setAction(intent.ACTION_SHUTDOWN); 
    shutdownIntent.putExtra(getResources().getString(R.string.progresStatus), value[0]); 

但如何把這個意圖到接收器?非常感謝

+0

[Android在內部/外部存儲中保存應用程序設置/數據]的可能重複(http://stackoverflow.com/questions/8119122/android-save-app-settings-data-in-internal-external-storage) – 323go

+0

我忘了說我正在使用服務,這是一個長時間的計算。所以如果用戶關掉手機,我需要在手機開機後立即開始計算 –

回答

1

由於Android正在發送Intent,因此您無法在此Intent中添加附加內容。你只能聽Intent。如果你需要一些數據,那麼你應該把這些數據放在一個共享的參數中,然後你可以在onReceive()中讀取。