Note that there are some explanatory texts on larger screens.

plurals
  1. POBroadcastReceiver makes animations lag
    text
    copied!<p>I have a <strong>MediaPlayer running in a Service</strong>. The <strong>service sends a broadcast to the activity</strong> with the current duration of the song every 250ms to update a SeekBar in the activity.</p> <pre><code>seekIntent = new Intent("com.someaction"); private Runnable sendUpdateToUI = new Runnable() { public void run() { LogMediaPosition(); handler.postDelayed(this, 250); } }; private void LogMediaPosition() { mediaPosition = mMediaPlayer.getCurrentPosition(); mediaMax = mMediaPlayer.getDuration(); seekIntent.putExtra("counter", mediaPosition); seekIntent.putExtra("mediamax", mediaMax); sendBroadcast(seekIntent); } </code></pre> <p>and <strong>in the activity</strong></p> <p><code>registerReceiver(broadcastReceiver, new IntentFilter("com.someaction"));</code></p> <pre><code>private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { updateUI(intent); } }; private void updateUI(Intent intent) { int seekProgress = intent.getIntExtra("counter", 0); int seekMax = intent.getIntExtra("mediamax", 0); songCurrentDurationLabel.setText(utils.millisecondsToTimer(seekProgress)); songProgressBar.setMax(seekMax); songProgressBar.setProgress(seekProgress); } </code></pre> <p>The activity also has a simple <strong>TranslateAnimation</strong>.</p> <pre><code>TranslateAnimation translate = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0); translate.setDuration(500); translate.setFillAfter(true); translate.setFillEnabled(true); btnName.startAnimation(translate); </code></pre> <p>When the receiver is registered, there is a very slight but noticeable lag in the TranslateAnimation. But if I comment out the registerReceiver() line in the activity, i.e., not letting the receiver to register thus not updating the SeekBar, the TranslateAnimation runs perfectly smooth.</p> <p>Any suggestion, how could this be resolved to get smooth animation even after having the receiver registered?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload