i know what it means to do too much work on the main thread. But i am unable to determine where this occurs in code.
i get the results before the screen goes black
W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x7f2b3b03d840, error=EGL_SUCCESS
I/Choreographer: Skipped 89 frames! The application may be doing too much work on its main thread.
W/EGL_emulation: eglSurfaceAttrib not implemented
W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x7f2b3b03d400, error=EGL_SUCCESS
D/OpenGLRenderer: endAllStagingAnimators on 0x7f2b3b1e9800 (RippleDrawable) with handle 0x7f2b43ec6200
W/EGL_emulation: eglSurfaceAttrib not implemented
W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x7f2b3b03d100, error=EGL_SUCCESS
i use ImageViews in my layout but must set images through code because when i set them through xml layout alot more work is done, and way more frames are skipped along with other errors.
my code:
public class GameActivity extends AppCompatActivity {
private List<MatchImageCard> gameCards;
private List<Drawable> gameOverCards;
private List<ImageView> staticImages;
private Game mMatchGame;
@Override
protected void onCreate( Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_card_game);
mMatchGame = new Game(12); //create game using class
assignStaticImages(); //get access to view normally set through xml layout
setStaticImages(); //set these views accessed
assignCards(); //access location of card view store in gameCards List
}
private void assignStaticImages(){
ImageView redStone = (ImageView) findViewById(R.id.red_img);
ImageView blueStone = (ImageView) findViewById(R.id.blue_img);
ImageView yellowStone = (ImageView) findViewById(R.id.yellow_img);
ImageView skull = (ImageView) findViewById(R.id.skull_img);
ImageView backgroundImage = (ImageView) findViewById(R.id.parchment_background);
ImageView backgroundScoreImage = (ImageView) findViewById(R.id.score_parchment);
ImageView spcl1 = (ImageView) findViewById(R.id.special_1);
ImageView spcl2 = (ImageView) findViewById(R.id.special_2);
ImageView oceanBackground = (ImageView) findViewById(R.id.ocean_image);
staticImages = new ArrayList<>();
staticImages.add(redStone);
staticImages.add(blueStone);
staticImages.add(yellowStone);
staticImages.add(skull);
staticImages.add(backgroundImage);
staticImages.add(backgroundScoreImage);
staticImages.add(spcl1);
staticImages.add(spcl2);
staticImages.add(oceanBackground);
}
private void setStaticImages(){
Drawable img1 = ResourcesCompat.getDrawable(getResources(), R.drawable.mouth, null);
Drawable img2 = ResourcesCompat.getDrawable(getResources(), R.drawable.nose, null);
Drawable img3 = ResourcesCompat.getDrawable(getResources(), R.drawable.eye, null);
Drawable img4 = ResourcesCompat.getDrawable(getResources(), R.drawable.display_skull, null);
Drawable img5 = ResourcesCompat.getDrawable(getResources(), R.drawable.parchment, null);
Drawable img6 = ResourcesCompat.getDrawable(getResources(), R.drawable.parchment, null);
Drawable img7 = ResourcesCompat.getDrawable(getResources(), R.drawable.penguin, null);
Drawable img8 = ResourcesCompat.getDrawable(getResources(), R.drawable.pirate, null);
Drawable img9 = ResourcesCompat.getDrawable(getResources(), R.drawable.island_ocean_1, null);
Drawable img10 = ResourcesCompat.getDrawable(getResources(), R.drawable.pirateship, null);
List<Drawable> images = new ArrayList<>();
images.add(img1);
images.add(img2);
images.add(img3);
images.add(img4);
images.add(img5);
images.add(img6);
images.add(img7);
images.add(img8);
images.add(img9);
for(int x = 0; x < staticImages.size(); x++){
ImageView img = staticImages.get(x);
img.setImageDrawable(images.get(x));
}
gameOverCards = new ArrayList<>();
gameOverCards.add(img10);
}
private void assignCards(){
List<ImageView> images = new ArrayList<>();
List<TextView> texts = new ArrayList<>();
ImageView img1 = (ImageView) findViewById(R.id.card1);
ImageView img2 = (ImageView) findViewById(R.id.card2);
ImageView img3 = (ImageView) findViewById(R.id.card3);
ImageView img4 = (ImageView) findViewById(R.id.card4);
ImageView img5 = (ImageView) findViewById(R.id.card5);
ImageView img6 = (ImageView) findViewById(R.id.card6);
ImageView img7 = (ImageView) findViewById(R.id.card7);
ImageView img8 = (ImageView) findViewById(R.id.card8);
ImageView img9 = (ImageView) findViewById(R.id.card9);
ImageView img10 = (ImageView) findViewById(R.id.card10);
ImageView img11 = (ImageView) findViewById(R.id.card11);
ImageView img12 = (ImageView) findViewById(R.id.card12);
images.add(img1);
images.add(img2);
images.add(img3);
images.add(img4);
images.add(img5);
images.add(img6);
images.add(img7);
images.add(img8);
images.add(img9);
images.add(img10);
images.add(img11);
images.add(img12);
TextView txt1 = (TextView) findViewById(R.id.card1_txt);
TextView txt2 = (TextView) findViewById(R.id.card2_txt);
TextView txt3 = (TextView) findViewById(R.id.card3_txt);
TextView txt4 = (TextView) findViewById(R.id.card4_txt);
TextView txt5 = (TextView) findViewById(R.id.card5_txt);
TextView txt6 = (TextView) findViewById(R.id.card6_txt);
TextView txt7 = (TextView) findViewById(R.id.card7_txt);
TextView txt8 = (TextView) findViewById(R.id.card8_txt);
TextView txt9 = (TextView) findViewById(R.id.card9_txt);
TextView txt10 = (TextView) findViewById(R.id.card10_txt);
TextView txt11 = (TextView) findViewById(R.id.card11_txt);
TextView txt12 = (TextView) findViewById(R.id.card12_txt);
texts.add(txt1);
texts.add(txt2);
texts.add(txt3);
texts.add(txt4);
texts.add(txt5);
texts.add(txt6);
texts.add(txt7);
texts.add(txt8);
texts.add(txt9);
texts.add(txt10);
texts.add(txt11);
texts.add(txt12);
gameCards = new ArrayList<>();
for(int x = 0; x < images.size(); x++){
ImageView img = images.get(x);
TextView txt = texts.get(x);
MatchImageCard card = new MatchImageCard(img, txt, x+1);
gameCards.add(card);
}
}
}
As you can see i have 9 ImageViews that i need to access at the beginning to setup layout. I don't know how this may be doing too much work since i access them once then forget about them. As well, i have 12 TextViews and 12 ImageViews that i need to constantly handle. to save time i created a class MatchImageCard, where each object contains 1 textView and 1 ImageView that exist in the xml Layout. Just hearing myself talk allows me to realize that i am doing a lot of work, but i don't know how to reduce the workload on the main thread. if i have to run new Threads, WHERE. on the 9 ImageViews in the beginning, is it where i assign them or Set them? I can make do with any advice offered.