SoFunction
Updated on 2025-03-01

Android clears data generated by SharedPreferences (instance code)



Definition:
        SharedPreferences preferences = null;
  editor = null;

  preferences = getSharedPreferences(TAG, Activity.MODE_PRIVATE);
  editor = ();
Save the playback position in onstop
 @Override
 protected void onStop() {
  (filePath, currentposition);
// Submit saved results
  (TAG, "onStop");
  ();
  ();
 }
seekto to the original location in onPrepared
public void onPrepared(MediaPlayer mp) {

 currentposition = (filePath, -1);
  if (currentposition != -1) {
   (currentposition);
   }

What I need later is to clear these records and clear them in ondestroy. It is worth noting that you must submit it when clearing, otherwise, if the data is not refreshed, you still need to maintain the original data. If you didn’t notice it at the beginning, you must commit it. It made me depressed. . .
 protected void onDestroy() {
  // TODO Auto-generated method stub

  if (clearshared) {
   ();
   ();
  }
  ();
 }