Java 保持android进度条或继续它
我想知道如何保持我的progressbar或简历的状态。让我解释一下,它是一个带有进度条的计时器,当用户关闭活动或关闭活动时,计时器作为后台服务启动(计时器工作正常),我希望当用户关闭活动或关闭应用程序时,当他返回时,进度条将恢复到原来的位置。现在,当它返回到计时器时,进度条返回到零。这是我的适配器代码,在这里进行课程和计时器服务 这是我保存进度条状态的方法Java 保持android进度条或继续它,java,android-studio,android-progressbar,countdowntimer,Java,Android Studio,Android Progressbar,Countdowntimer,我想知道如何保持我的progressbar或简历的状态。让我解释一下,它是一个带有进度条的计时器,当用户关闭活动或关闭活动时,计时器作为后台服务启动(计时器工作正常),我希望当用户关闭活动或关闭应用程序时,当他返回时,进度条将恢复到原来的位置。现在,当它返回到计时器时,进度条返回到零。这是我的适配器代码,在这里进行课程和计时器服务 这是我保存进度条状态的方法 private static SharedPreferences.Editor pref; private static int save
private static SharedPreferences.Editor pref;
private static int saveProgressBarState;
private static SharedPreferences getProgressBarState;
private CountDownTimer countDown(final long time, final ProgressBar lessonProgress, long originalTimerSize) {
final int timerLengthInSecond = (int) time / 1_000;
lessonProgress.setMax((int) originalTimerSize / 1_000);
return new CountDownTimer(time, 1000) {
@Override
public void onTick(long l) {
long secondRemaining = l / 1_000;
lessonProgress.setProgress((int) (timerLengthInSecond - secondRemaining));
//Getting progress of progress bar
saveProgressBarState = lessonProgress.getProgress();
}
@Override
public void onFinish() {
lessonProgress.setProgress(timerLengthInSecond);
}
};
}
//this method is called when onPause() is called on the activity
public static void runLessonTimerInBackground(Context context) {
pref = context.getSharedPreferences("LESSONPROGRESS", MODE_PRIVATE).edit();
pref.putInt("savedprogress", progressBarStateSave);
pref.apply();
}
我想获得保存的progressbarstate并恢复原来的进度,然后继续进度您需要在
onResume()中添加这些链接
我假设您可以调整并将其应用到课程的实际进度中
int lastProgress = pref.getInt("savedprogress", 0); //0 is default value
lessonProgress.setProgress(lastProgress); //this will set the progress
//here you might also need to do some other stuff related to your code and req
//you can also resume your lesson video from here, etc.
如果您想在sharePref中保存多个课程进度,我建议您像这样保存进度
String progressPrefName = "savedProgress_" + lessonID; //here lessonID is lesson's unique ID
pref.putInt(progressPrefName, progressBarStateSave); // here pass the name which can be "savedProgress_1" referring to lesson with ID 1
然后你可以像这样得到它
String progressPrefName = "savedProgress_" + lessonID;
int lastProgress = pref.getInt(progressPrefName, 0); //0 is default value
lessonProgress.setProgress(lastProgress); //this will set the progress
你需要在你的
onResume()中添加这些链接
int lastProgress = pref.getInt("savedprogress", 0); //0 is default value
lessonProgress.setProgress(lastProgress); //this will set the progress
//here you might also need to do some other stuff related to your code and req
//you can also resume your lesson video from here, etc.
如果您想在sharePref中保存多个课程进度,我建议您像这样保存进度
String progressPrefName = "savedProgress_" + lessonID; //here lessonID is lesson's unique ID
pref.putInt(progressPrefName, progressBarStateSave); // here pass the name which can be "savedProgress_1" referring to lesson with ID 1
然后你可以像这样得到它
String progressPrefName = "savedProgress_" + lessonID;
int lastProgress = pref.getInt(progressPrefName, 0); //0 is default value
lessonProgress.setProgress(lastProgress); //this will set the progress
将progressBar位置保存到,获取
onResume()上的位置并设置it@RahulGaur我在SharedReferences中使用getProgress()方法保存计时器进度条状态,如何恢复并继续进度?@RahulGaur我编辑过请check@RahulGauronResume()中仍然没有任何内容。我无法参加这个聚会。我请求帮助以便能够完成此部分将progressBar位置保存到,在onResume()上获取位置并设置it@RahulGaur我在SharedReferences中使用getProgress()方法保存计时器进度条状态,如何恢复并继续进度?@RahulGaur我编辑过请check@RahulGauronResume()中仍然没有任何内容这是我办不到的聚会。我请求帮助来完成这部分