Okhelp.cz

Recepty, články, nápady, programování. Dříve dum-zahrada, finance, internet a know-how.okhelp.cz Pro lepší výsledky hledání používejte i diakritiku.

The application may be doing too much work on its main thread


AD MOB

Warning: The application may be doing too much work on its main thread
Try this sorce code:

import android.os.StrictMode;

public class MyActivity extends Activity {
	static{
		StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
		StrictMode.setThreadPolicy(policy);
	}
	@Override
    public void onCreate(Bundle savedInstanceState) {
//.................. etc.


397LW NO topic_id




AD

Další témata ....(Topics)


385

EditText.setOnKeyListener not working on maxLines EditText | edittext-setonkeylistener-not-working-on-maxlines-edittext


Check this in XML file if use singleLine
singleLine change to maxLines (1 if singleLine)
declare inputType


        android:maxLines="1"
        android:inputType="text"

62

Date Calendar Java Android Example | date-calendar-java-android-example


Calendar cal = new GregorianCalendar(), int year = cal.get(Calendar.YEAR),
ERA, MONTH, DAY_OF_MONTH, DAY_OF_WEEK, Android example code.

public class MainActivity extends Activity {
TextView txtV;
	Context cntx;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        txtV = (TextView)findViewById(R.id.idLabel);
        cntx = this;
        Calendar cal = new GregorianCalendar();

     int era = cal.get(Calendar.ERA);  // 0 B.C. before Christ, 1 Anno Domini              
     txtV.setText(txtV.getText() +"

" + era); int year = cal.get(Calendar.YEAR); // 2011 txtV.setText(txtV.getText() +"
" + year); int month = cal.get(Calendar.MONTH); // 0 is Januar txtV.setText(txtV.getText() +"
" + month); int day = cal.get(Calendar.DAY_OF_MONTH); // 1 to 31 txtV.setText(txtV.getText() +"
" + day); int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK); // 1=Sunday, 2=Monday ... txtV.setText(txtV.getText() +"
" + dayOfWeek); } }
164

Immutable bitmap passed to Canvas constructor - Android error | immutable-bitmap-passed-to-canvas-constructor-android-error


Try this source code:

Bitmap myBitmap = BitmapFactory.decodeResource(getResources(),R.drawable.my_image)
.copy(Bitmap.Config.ARGB_8888, true);
Canvas c = new Canvas(myBitmap);
// etc.  ....... 


Issue: Immutable bitmap passed to Canvas constructor
Solution: Bitmap myBitmap = BitmapFactory.decodeResource(getResources(),R.drawable.my_image)
.copy(Bitmap.Config.ARGB_8888, true);
52

ImageView change image Android example | imageview-change-image-android-example


How to change the image dynamically in ImageView and button setOnClickListener Android sample.


Main.java


ipackage cz.okhelp.my_game;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;


public class Main extends Activity {
private ImageView hImageViewSemafor;
private Button hButton;
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        hImageViewSemafor = (ImageView)findViewById(R.id.idImageViewSemafor);
        hButton = (Button) findViewById(R.id.idBtnChangeImage);
        hButton.setOnClickListener(mButtonChangeImageListener);
 
 
       
       
    }
	
    View.OnClickListener mButtonChangeImageListener = new OnClickListener() {
        public void onClick(View v) {
                // setImageResource will change image in ImageView
        	hImageViewSemafor.setImageResource(R.drawable.semafor_green);
            
        }
    };

}



main.xml
Put into res/drawable this pictures:
semafor
semafor



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="//schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    />
    
       <ImageView
            android:src="@drawable/semafor_red"
            android:id="@+id/idImageViewSemafor"
            android:background="#66FFFFFF"
            android:adjustViewBounds="true"
            android:maxWidth="47dip"
            android:maxHeight="91dip"
            android:padding="10dip"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />    
    
</LinearLayout>






314

Every fragment must have an empty constructor Android Java Class | every-fragment-must-have-an-empty-constructor-android-java-class


You have to add constructor!

    public static class YourFragment extends Fragment {
    //you have to add constructor!!!!!	
    public YourFragment(){}

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            View view = inflater.inflate(R.layout.activity_main, container, false);

            return view;
        }   

    }



Editace: 2013-12-09 10:11:46
Počet článků v kategorii: 397
Url:the-application-may-be-doing-too-much-work-on-its-main-thread

AD
11 Share
Share
Tweet