当前位置: 动力学知识库 > 问答 > 编程问答 >

crash - Android skipped frames too much work on main thread

问题描述:

My MainActivity is a tab layout which has three tabs. First tab is crashing because of "Android skipped frames too much work on main thread"

Here is my code : It has three images, it animates after few seconds randomly.

And when user click on any of the images, new activity class loads up, each image has its own activity class.

My plan was to add 10 or more images in a array, but with three images my app is crashing not sure if it can handle 10 images.

Can anyone please help to find what might be the reason behind skipped frames and app crashing.

public class HomeAnimation extends Fragment implements AnimationListener {

public HomeAnimation(){}

private static boolean flag = false;

Animation anim;

private Handler handler;

public ImageSwitcher mSwitcher,mSwitcher1;

int textToShow[] = {

R.drawable.dabangg, R.drawable.car, R.drawable.ramleela

};

int messageCount = textToShow.length;

int currentIndex = -1;

Timer timer = new Timer();

Handler hander = new Handler();

Runnable runnable = new Runnable(){

public void run() {

updateTextView();

hander.postDelayed(this, 4000);

}

};

@Override

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

View v = inflater.inflate(R.layout.imgswitch, container, false);

mSwitcher = (ImageSwitcher) v.findViewById(R.id.imageSwitcher1);

mSwitcher.setFactory(mFactory);

anim = AnimationUtils.loadAnimation(getActivity(),R.anim.fade_in);

anim.setAnimationListener(this);

return v;

}

网友答案:

It is likely that the images you are using are too big. Are they Jpeg or png. In an app you should be using optimized png files for images. I have found that very small Jpeg images will cause this error.

The error is typically caused by an overloaded system. It is unable to process the large images or code within the alotted Time. I've also seen this on an infinite loop problem.

分享给朋友:
您可能感兴趣的文章:
随机阅读: