preferences = getSharedPreferences(TAG, Activity.MODE_PRIVATE);
editor = preferences.edit();
在onstop里面保存播放位置
@Override
protected void onStop() {
editor.putInt(filePath, currentposition);
// 提交保存的結果
Log.e(TAG, "onStop");
editor.commit();
super.onStop();
}
在onPrepared中seekto到原來位置
public void onPrepared(MediaPlayer mp) {
currentposition = preferences.getInt(filePath, -1);
if (currentposition != -1) {
mUvv.seekTo(currentposition);
}
后面的話,我需要的是清除這些記錄,在ondestroy中清除。 值得注意的地方是清除的時候也要提交,不然的話,數據沒刷新還是保持原來的數據,剛開始沒有注意到清除也要commit。搞得我郁悶。。。
protected void onDestroy() {
// TODO Auto-generated method stub
if (clearshared) {
editor.clear();
editor.commit();
}
super.onDestroy();
}
新聞熱點
疑難解答
圖片精選