0

I am making a simple game.

1st screen is splash screen with just 2 images, 1 progress bar and a background image.

2nd screen is Options choose from different levels / options of games. It has few TextFields, Spinner Items , 2 images and 1 background. These images and background images are same as of splash screen.

From the options screen there is two ways to proceed with New Activity in game either choose "3x3"(MainActivity.class Activity) or 4X4(bigmain.class Activity). Both these activities are playing screen and contains 1 same image and a grid layout fitted with few ImageViews.

Both MainActivity and bigmain has onClick() method of grid layout. All the further game processing like checking if anywone wins or not, different methods to invoke on different player's turn. So both of them has lots of code and all in single java class file. Is this the reason ? If so then how to overcome it. I am attaching my logcat report when I install app in my phone through adb. See the bold text.

07-01 17:41:18.454 7003-7003/bt4u.com.pokemonbattles W/System:   ClassLoader referenced unknown path: /data/app/bt4u.com.pokemonbattles-2/lib/arm64
07-01 17:41:18.491 7003-7003/bt4u.com.pokemonbattles W/System: ClassLoader referenced unknown path: /data/app/bt4u.com.pokemonbattles-2/lib/arm64
07-01 17:41:18.492 7003-7003/bt4u.com.pokemonbattles I/LoadedApk: No resource references to update in package common
07-01 17:41:18.493 7003-7003/bt4u.com.pokemonbattles I/LoadedApk: No resource references to update in package com.rr.neptune
07-01 17:41:46.642 7332-7332/bt4u.com.pokemonbattles W/System: ClassLoader referenced unknown path: /data/app/bt4u.com.pokemonbattles-2/lib/arm64
07-01 17:41:47.290 7332-7332/bt4u.com.pokemonbattles W/System: ClassLoader referenced unknown path: /data/app/bt4u.com.pokemonbattles-2/lib/arm64
07-01 17:41:47.291 7332-7332/bt4u.com.pokemonbattles I/LoadedApk: No resource references to update in package common
07-01 17:41:47.292 7332-7332/bt4u.com.pokemonbattles I/LoadedApk: No resource references to update in package com.rr.neptune
**07-01 17:41:47.824 7332-7332/bt4u.com.pokemonbattles I/System.out: Splash screen activity (splash.java)**
07-01 17:41:47.834 7332-7363/bt4u.com.pokemonbattles D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
07-01 17:41:47.863 7332-7363/bt4u.com.pokemonbattles I/Adreno: QUALCOMM build                   : 6d30364, I5d4b06969f
07-01 17:42:12.187 7660-7686/bt4u.com.pokemonbattles I/OpenGLRenderer: Initialized EGL, version 1.4
07-01 17:42:15.294 7660-7660/bt4u.com.pokemonbattles I/System.out: Game options activity (gameoptions.class)
07-01 17:42:15.350 7660-7660/bt4u.com.pokemonbattles D/android.widget.GridLayout: horizontal constraints: x1-x0>=243, x2-x1>=0, x3-x2>=0, x4-x3>=430, x4-x0<=656 are inconsistent; permanently removing: x4-x0<=656. 
**07-01 17:42:17.615 7660-7660/bt4u.com.pokemonbattles I/Choreographer: Skipped 125 frames!  The application may be doing too much work on its main thread.**
**07-01 17:48:20.373 7660-7660/bt4u.com.pokemonbattles I/System.out: Game Option A Screen (MainActivity.class)**
07-01 17:48:20.601 7660-7686/bt4u.com.pokemonbattles D/OpenGLRenderer: endAllStagingAnimators on 0x55c0c40f40 (RippleDrawable) with handle     0x55c08e70b0
**07-01 17:48:37.333 7660-7660/bt4u.com.pokemonbattles I/System.out: Game Option B Screen (bigmain.class)**
07-01 17:48:37.358 7660-7660/bt4u.com.pokemonbattles D/android.widget.GridLayout: vertical constraints: y4-y0>=900, y4-y3<=230, y3-y2<=230, y2-y1<=224, y1-y0<=210 are inconsistent; permanently removing: y4-y3<=230. 
07-01 17:48:37.685 7660-7686/bt4u.com.pokemonbattles D/OpenGLRenderer: endAllStagingAnimators on 0x55c0c40f40 (RippleDrawable) with handle 0x55c0d44e20
  • 2
    Possible duplicate of [The application may be doing too much work on its main thread](http://stackoverflow.com/questions/14678593/the-application-may-be-doing-too-much-work-on-its-main-thread) – Harshad Pansuriya Jul 01 '16 at 12:39
  • have you tried starting a new thread for processing? As far as I remember you shouldn't use the mainthread for long/heavy operations. Try to post a runnable. – Memme Jul 01 '16 at 13:10
  • any example that you can provide for doing so – Shubham Singh Jul 01 '16 at 15:58

2 Answers2

1

Application is doing too much work in main Thread means you are doing some high task like large data object fetching and converting or loading with large Image that time this error is occure.

More explnation : it may be because of some heavy processing that you are doing at the heart of your application or DB access or any other thing which causes the thread to stop for a while

Solution : to solve that problem simply create Multithreading.

UnderStandMent :

lets say you have for loop inside on Button so you have set it `OnClickListener` like this

  @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_inventory);

    button.setOnclickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                   for(i=0;i<1000;i++){
                   --  Print i

                       i++;                   
                     }

                   }
            });

   }

like this one no put after click event any other unusable code inside that check that way..

Harshad Pansuriya
  • 20,189
  • 8
  • 67
  • 95
0

It means you are doing heavy task on your main UI thread. Which causes ANR (Application not responding) because you are running a process on the UI thread which takes a long time. During this time the GUI (Graphical User Interface) will lock up which will result in anything the user presses will not be actioned.

You should use another thread for heavy task.

Better Approach will be using AsyncTask .

private class AsyncCaller extends AsyncTask<Void, Void, Void>
{
    ProgressDialog pdLoading = new ProgressDialog(AsyncExample.this);

    @Override
    protected void onPreExecute() {
        super.onPreExecute();

        //this method will be running on UI thread
        pdLoading.setMessage("\tLoading...");
        pdLoading.show();
    }
    @Override
    protected Void doInBackground(Void... params) {

        //this method will be running on background thread so don't update UI frome here
        //do your long running http tasks here,you dont want to pass argument and u can access the parent class' variable url over here


        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        super.onPostExecute(result);

        //this method will be running on UI thread

        pdLoading.dismiss();
    }

    }
abdul khan
  • 843
  • 2
  • 7
  • 24