This is my first Android/Java app. I am using the first answer here to try to initiate a repeating task, updating a seekbar ("timeSlider") to show progress as an audio file plays. Here is my code (eliminating a few irrelevant lines):
private int timeSliderInterval = 1000; // 1 second
private Handler timeSliderHandler;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_play);
Intent intent = getIntent();
Runnable doUpdateTimeSlider = new Runnable() {
@Override
public void run() {
timeSliderHandler.postDelayed(doUpdateTimeSlider, timeSliderInterval);
updateTimeSlider();
}
};
void startUpdateTimeSlider() {
doUpdateTimeSlider.run();
}
void stopUpdateTimeSlider() {
timeSliderHandler.removeCallbacks(doUpdateTimeSlider);
}
final SeekBar timeSlider = (SeekBar) findViewById(R.id.timeSlider);
if (timeSlider != null) {
timeSliderHandler = new Handler();
startUpdateTimeSlider();
}
@Override
public void onDestroy() {
super.onDestroy();
stopUpdateTimeSlider();
}
The project does not display in the emulator. Tooltips show these errors:
In addition, the startUpdateTimeSlider
and stopUpdateTimeSlider
functions are showing this error in tooltips:
Also, in the Run window, I'm getting:
emulator: emulator window was out of view and was recentered
emulator: ERROR: _factory_client_recv: Unknown camera factory query name in ' '
Any help will be greatly appreciated!
First issue is self explained, you need to add final
modifier.
final Runnable doUpdateTimeSlider = ...
Second one - move startUpdateTimerSlider()
method, now its inside onCreate()
method
Looks like you missed }
:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_play);
Intent intent = getIntent();
Runnable doUpdateTimeSlider = new Runnable() {
@Override
public void run() {
timeSliderHandler.postDelayed(doUpdateTimeSlider, timeSliderInterval);
updateTimeSlider();
}
};
}//<--------HERE
void startUpdateTimeSlider() {
doUpdateTimeSlider.run();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.