0

I'm building my first app, but after adding a few layout stuff a DrawerLayout to be exact it started to give me an error:

I/Choreographer: Skipped 126 frames! The application may be doing too much work on its main thread

This here is my layout code:

<!-- The main content view -->

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">




<!-- ładowanie toolbara -->
<include
 layout="@layout/tool_bar"

/>
<include
layout="@layout/twoja_strona"

/>
<RelativeLayout


    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:layout="http://schemas.android.com/apk/res-auto"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="pl.webimpuls.wicms.MainActivity"
    android:background="#e7e7e7">




<GridLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:columnCount="2"
    android:rowCount="4"
    android:id="@+id/gridLayout">

        <RelativeLayout android:layout_width="fill_parent"
            android:orientation="horizontal">
        <RelativeLayout
        android:layout_width="160dp"
        android:layout_height="100dp"
        android:layout_row="1"
        android:layout_column="1"
            android:background="@color/background_material_light"
            android:layout_marginRight="5dp"
            android:layout_gravity="center|left"
            android:layout_alignParentLeft="true"
            android:layout_marginLeft="0dp"
            android:layout_alignParentTop="true"
            android:layout_marginTop="0dp"
            android:id="@+id/dodaj_wpis"
            android:clickable="true"
            android:onClick="dodajaaktualnosc">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/imageView2"
                android:src="@mipmap/dodaj_wpis"
                android:layout_above="@+id/textView"
                android:layout_alignParentRight="true"
                android:layout_alignParentEnd="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_alignParentTop="true" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                      android:textAppearance="?android:attr/textAppearanceMedium"
                android:text="Dodaj Wpis"
                android:id="@+id/textView"
                android:textAlignment="center"
                android:layout_alignParentBottom="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true" />
        </RelativeLayout>
        <RelativeLayout
            android:layout_width="160dp"
            android:layout_height="100dp"
            android:layout_row="1"
            android:layout_column="0"
            android:background="@color/background_material_light"
            android:layout_alignParentTop="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true"
            android:id="@+id/lista_aktualnosci"
            android:clickable="true"
            android:onClick="czytajaktualnosc">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/imageView3"
                android:src="@mipmap/lista_aktualnosci"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_alignParentTop="true"
                android:layout_above="@+id/textView2"
                android:layout_alignParentRight="true"
                android:layout_alignParentEnd="true" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text="Lista Aktualności"
                android:id="@+id/textView2"
                android:textAlignment="center"
                android:singleLine="true"
                android:layout_alignParentBottom="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true" />
        </RelativeLayout>

        </RelativeLayout>
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:layout_row="2"
            android:layout_column="0"
            android:layout_marginBottom="10dp"
            android:background="@color/background_material_light"
            android:layout_marginTop="10dp"
            android:id="@+id/twoje_leady"
            android:clickable="true"
            android:onClick="leady">

            <ImageView
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:id="@+id/imageView4"
                android:src="@mipmap/twoje_leady"
                android:layout_alignParentTop="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_marginLeft="30dp"
                android:layout_alignParentBottom="true" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text="Twoje Leady"
                android:id="@+id/textView3"
                android:textAlignment="center"
                android:layout_centerVertical="true"
                android:layout_toRightOf="@+id/imageView4"
                android:layout_toEndOf="@+id/imageView4"
                android:layout_marginLeft="46dp"
                android:layout_marginStart="46dp" />
        </RelativeLayout>
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:layout_row="3"
            android:layout_column="0"
            android:background="@color/background_material_light"
            android:id="@+id/otworz_strone"
            android:clickable="true"
            android:onClick="otworzstrone">

            <ImageView
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:id="@+id/imageView5"
                android:src="@mipmap/otworz_strone"
                android:layout_alignParentTop="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_marginLeft="30dp"
                android:layout_alignParentBottom="true" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text="Otwórz Stronę"
                android:id="@+id/textView4"
                android:textAlignment="center"
                android:layout_centerVertical="true"
                android:layout_toRightOf="@+id/imageView5"
                android:layout_toEndOf="@+id/imageView5"
                android:layout_marginLeft="46dp"
                android:layout_marginStart="46dp" />

        </RelativeLayout>

    </GridLayout>
<include
    layout="@layout/stopka"
    android:layout_alignParentBottom="true"
    android:layout_height="50dp"
    android:layout_width="wrap_content">

</include>
</RelativeLayout>

</LinearLayout>

<include
layout="@layout/menu_wysuwajace"></include>

</android.support.v4.widget.DrawerLayout>

Please I need to knwo what's going on.

Here's my java it's not that massive I think. How could I run it's on async?

package pl.webimpuls.wicms;

import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.MotionEvent;
import android.view.View;
import android.widget.RelativeLayout;
import com.crashlytics.android.Crashlytics;
import io.fabric.sdk.android.Fabric;

public class MainActivity extends AppCompatActivity {

private Toolbar toolbar;



@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Fabric.with(this, new Crashlytics());
    setContentView(R.layout.activity_main);

    RelativeLayout dw = (RelativeLayout)findViewById(R.id.dodaj_wpis);



}


public void dodajaaktualnosc(View view)
{
    Intent dodaj = new Intent(MainActivity.this, aktualnosci_dodaj.class);
    startActivity(dodaj);
}

public void czytajaktualnosc(View view)
{
    Intent czytaj = new Intent(MainActivity.this, aktualnosci.class);
    startActivity(czytaj);
}
public void leady(View view)
{
    Intent leady = new Intent(MainActivity.this, aktualnosci.class);
    startActivity(leady);
}
public void otworzstrone(View view)
{
    Intent otworzurl = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.webimpuls.pl"));
    startActivity(otworzurl);
}

}

Fadlan
  • 51
  • 6
  • Post your logcat message (i.e. the full error message you got) – Farbod Salamat-Zadeh Jun 18 '16 at 11:47
  • I/Choreographer: Skipped 126 frames! The application may be doing too much work on its main thread. And everything is lagging while using navigation drawer – Fadlan Jun 18 '16 at 11:52
  • 2
    There is already an answer for your question [here](http://stackoverflow.com/questions/14678593/the-application-may-be-doing-too-much-work-on-its-main-thread?rq=1) – Farbod Salamat-Zadeh Jun 18 '16 at 11:53
  • There is something about using separate threads but I still have no idea how. – Fadlan Jun 18 '16 at 11:59
  • Use background thread for long task and add a callback when your background task is done update UI thread. – Sohail Zahid Jun 18 '16 at 12:17
  • How do I assign thread for long task and add a callback? I'm pretty new to all of this. – Fadlan Jun 18 '16 at 12:20
  • Callbacks are just java interfaces. AsyncTask allows you to run code off the main thread. Stick them together. http://stackoverflow.com/questions/9963691/android-asynctask-sending-callbacks-to-ui – OneCricketeer Jun 18 '16 at 12:43
  • Alternatively, your images may be too large. (also said on that post that addresses the problem) – OneCricketeer Jun 18 '16 at 12:46
  • I will add my Java code from MainActivity becouse I think it's not that resource taking. – Fadlan Jun 18 '16 at 13:02

1 Answers1

0

You can run long running tasks on separate worker thread for that you can use asyntasks, volley Library, retrofit library etc for network calls

Uma Achanta
  • 3,669
  • 4
  • 22
  • 49