1

Basically I'm trying to learn java and android app development. Recently I created a new project and designed a simple layout with a button in it and loaded it with main activity.

Now I'm getting following errors without even implementing button function and stuff etc.. it's just loading and displaying layout but it is taking too much time. For example: when i load it on simulator or on my person device.. it takes about 10 seconds to load and then when i click a button application skips frames..

01/08 09:19:48: Launching app
No apk changes detected since last installation, skipping installation of C:\Users\nouma\AndroidStudioProjects\MediEase\app\build\outputs\apk\app-debug.apk
$ adb shell am force-stop com.example.nouma.mediease
$ adb shell am start -n "com.example.nouma.mediease/com.example.nouma.mediease.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Connected to process 3520 on device Nexus_5X_API_23 [emulator-5554]
W/System: ClassLoader referenced unknown path: /data/app/com.example.nouma.mediease-2/lib/x86
D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true

                  [ 01-08 09:19:49.686  3520: 3520 D/         ]
                  HostConnection::get() New Host Connection established 0xaab6ddc0, tid 3520


                  [ 01-08 09:19:49.746  3520: 3534 D/         ]
                  HostConnection::get() New Host Connection established 0xaff0d4e0, tid 3534
I/OpenGLRenderer: Initialized EGL, version 1.4
W/EGL_emulation: eglSurfaceAttrib not implemented
W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xaa392b60, error=EGL_SUCCESS
I/Choreographer: Skipped 213 frames!  The application may be doing too much work on its main thread.
I/Choreographer: Skipped 91 frames!  The application may be doing too much work on its main thread.
I/Choreographer: Skipped 75 frames!  The application may be doing too much work on its main thread.
I/Choreographer: Skipped 73 frames!  The application may be doing too much work on its main thread.
I/Choreographer: Skipped 67 frames!  The application may be doing too much work on its main thread.
I/Choreographer: Skipped 77 frames!  The application may be doing too much work on its main thread.
I/Choreographer: Skipped 89 frames!  The application may be doing too much work on its main thread.

Code

package com.example.nouma.mediease;

    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
import android.content.Intent;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    //private Button mainbutton;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

       /* mainbutton = (Button)findViewById(R.id.begin_button);

        mainbutton.setOnClickListener(
                new Button.OnClickListener(){
                    public void onClick(View v){
                        startMain();
                    }
                }
        );*/
    }

    /*
    *public void onClick(View v) {
  new Thread(new Runnable() {
    public void run() {
      Bitmap b = loadImageFromNetwork();
      mImageView.setImageBitmap(b);
    }
  }).start();
}
    * */
    void startMain(){
        Intent i = new Intent(this, introActivity.class);
        startActivity(i);
        finish();
    }
}

XML FILE: http://pastebin.com/cQ6fSmvg

Nouman Arshad
  • 101
  • 1
  • 2
  • 10
  • 1
    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) – Sadiq Md Asif Jan 08 '17 at 04:43
  • please put your xml here – masoud vali Jan 08 '17 at 05:11
  • @Nouman Arshad is that all you have and is this the launching activity or did you had previous ones and then load this one? I see only a sentcontent view and all other lines are commented so with that you get this error.IF yes your xml has issues post it here – Charuක Jan 08 '17 at 05:25
  • @Charuka xml file is at http://pastebin.com/cQ6fSmvg – Nouman Arshad Jan 08 '17 at 05:37
  • @Nouman Arshad click on the background image `mediease_background` and tell me the size i think that is something big in size remove that image and add `android:background="#000"` run and see if you get the error – Charuක Jan 08 '17 at 05:39
  • @Charuka Yes, image is 1920x1080 and issue is solved by removing it. Why is this image causing trouble? actually i wanted to use high resolution image so that it displays on other screen size as well too.. – Nouman Arshad Jan 08 '17 at 05:55
  • @Nouman Arshad I will post an answer – Charuක Jan 08 '17 at 05:57

1 Answers1

0

Since there is no such code error should came from the xml. In your XML most possible case to trow this error is your background image

what might be happening is that the OS is trying to do a lot of processing on your images, which you may have chosen of a high resolution. What you can do is try to create multiple resolution of your image (mdpi,hdpi,xhdpi,xxhdpi). android supporting multiple resolution with multiple layout folder

you can take the standard size of the image as mdpi and increase their sizes in the ratio of 1.5,2,3 respectively for hdpi,xhdpi,xxhdpi. when you have these images put them in the drawable folders if you don't have them create them by yourself. Sometimes this may even cause OOM's in android. one article explaining it

First try to add below line in your manifest and see it it helps

 <application android:largeHeap="true"

If it does not help and you have only one image to use in all devices you need to decoding the content itself to that you can use this https://stackoverflow.com/a/823966/5188159 So if you decide to go with scale downing you need to set background programmatically not using your xml

Bitmap myBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.amanda); // Replace your image name with my one
BitmapDrawable bitmapDrawable  = new  BitmapDrawable(MainActivity.this.getResources(), myBitmap);
relativeLayout.setBackground(bitmapDrawable);  // Replace your activity with my main 
Community
  • 1
  • 1
Charuක
  • 12,953
  • 5
  • 50
  • 88