我有2个无限跳过帧的动画绘图。
它运行但跳帧很麻烦,使程序变慢。
背景部分并发标记扫描是什么意思?
我该如何解决这个问题?
记录结果
I/art: Background partial concurrent mark sweep GC freed 46(1696B) AllocSpace objects, 0(0B) LOS objects, 6% free, 57MB/61MB, paused 20.931ms total 27.744ms
I/art: Background partial concurrent mark sweep GC freed 18(736B) AllocSpace objects, 0(0B) LOS objects, 5% free, 65MB/69MB, paused 6.151ms total 19.613ms
I/Choreographer: Skipped 47 frames! The application may be doing too much work on its main thread.
I/Choreographer: Skipped 42 frames! The application may be doing too much work on its main thread.
I/Choreographer: Skipped 46 frames! The application may be doing too much work on its main thread.
I/Choreographer: Skipped 43 frames! The application may be doing too much work on its main thread.
这是程序:
public class IntroActivity extends AppCompatActivity {
private AnimationDrawable animateOcean;
private AnimationDrawable animateSkull;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_intro);
new CreateAnimationDrawableOcean().execute();
new CreateAnimationDrawableSkull().execute();
Runnable runnable = new Runnable() {
@Override
public void run() {
for (int i = 0; i <= 10; i++) {
final Drawable img = ResourcesCompat.getDrawable(getResources(), R.drawable.map, null);
final ImageView map = (ImageView) findViewById(R.id.map_img);
map.post(new Runnable() {
@Override
public void run() {
map.setImageDrawable(img);
}
});
}
}
};
new Thread(runnable).start();
}
//turns on and off background animation of ocean
private void animateOcean(boolean stat){
final ImageView oceanBackground = (ImageView) findViewById(R.id.OceanView);
if(stat){
oceanBackground.post(new Runnable() {
@Override
public void run() {
animateOcean.start();
}
});
}
else{
oceanBackground.post(new Runnable() {
@Override
public void run() {
animateOcean.stop();
}
});
}
}
//turns off and on animation of skull with stones
private void animateSkull(boolean stat){
final ImageView skull = (ImageView) findViewById(R.id.skull_image);
if(stat){
skull.post(new Runnable() {
@Override
public void run() {
animateSkull.start();
}
});
}
else
{
skull.post(new Runnable() {
@Override
public void run() {
animateSkull.stop();
}
});
}
}
private class CreateAnimationDrawableOcean extends AsyncTask<Void, Void, Drawable>{
@Override
protected Drawable doInBackground(Void... voids) {
Drawable img = ResourcesCompat.getDrawable(getResources(), R.drawable.ocean_movie, null);
animateOcean = (AnimationDrawable) img;
return img;
}
@Override
protected void onPostExecute(Drawable drawable) {
super.onPostExecute(drawable);
ImageView oceanBackground = (ImageView) findViewById(R.id.OceanView);
oceanBackground.setImageDrawable(drawable);
animateOcean(true);
}
}
private class CreateAnimationDrawableSkull extends AsyncTask<Void, Void, Drawable>{
@Override
protected Drawable doInBackground(Void... voids) {
Drawable img = ResourcesCompat.getDrawable(getResources(), R.drawable.skull_movie, null);
animateSkull = (AnimationDrawable) img;
return img;
}
@Override
protected void onPostExecute(Drawable drawable) {
ImageView skull = (ImageView) findViewById(R.id.skull_image);
skull.setImageDrawable(drawable);
animateSkull(true);
}
}
}