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.

Android Studio reduce memory usage of PC


File->Settings->Plugins and disable some plugins:

  • Google Cloud Testing

  • Google Cloud Tools Core

  • Google Cloud Tools for Android Studio

  • CVS Integration

  • Git Integration

  • GitHub

  • hg4idea

  • Subversion Integration

Use Emulator AVD with small memmory usage. For example: Virtual tablet with hight resolution have big memmory usage. Virtual phone with 240x320 resolution have small memmory usage.

Use instaed of Emulator, real device connected by USB (smarphone Samsung Galaxy or other recommended by Google whit debugable mode).

If you notice that Android Studio works slowly, consider the possibility to reduce the number of folders under antivirus protection.
Each antivirus check in your project consumes resources. You can significantly improve the performance, if you exclude certain folders from the antivirus protection.

397LW NO topic_id


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


How set focus on View Android development example | how-set-focus-on-view-android-development-example

Set focus on a View in Android application example source code for Button, EditText, View, TextView, isFocused(), requestFocus() .

// set focus on Button Android example
 private Button mRightButton;
 mRightButton = (Button) a.findViewById(R.id.rightButton);
// boolean isFocused() 
boolean b = mRightButton.isFocused(); // true or false

// set focus on TextView directly Android example
((TextView) findViewById(R.id.myText)).requestFocus();

// set focus on View Android example
private View mView;
mView = findViewById(R.id.showAll);

// set focus on EditText Android example
private EditText mEdit;
mEdit = (EditText)findViewById(R.id.myEdit);

Cannot resolve symbol HttpGet,HttpClient,HttpResponce in Android Studio | cannot-resolve-symbol-httpgethttpclienthttpresponce-in-android-studio

Try this code:

final String ERROR = "my error message....";

 private class DownloadWebPageTask extends AsyncTask<String, Void, String> {
// some code and method ..... see AsyncTask

        protected String doInBackground(String... urls) {

              URL urlL = null;
                try {
                    urlL = new URL(url);//"//chmi.cz..../"
                    HttpURLConnection urlConnection = null;
                    try {
                         urlConnection = (HttpURLConnection) urlL.openConnection();
                        InputStream in = new BufferedInputStream(urlConnection.getInputStream());
                      response =  readStream(in);
                        return response;
                    } catch (IOException e) {
                        //throw new RuntimeException(e);

                    } finally {
                        if(urlConnection != null)
                        return ERROR;
                } catch (MalformedURLException e) {
                    return ERROR;
            return response;

        private String readStream(InputStream is) {
            try {
                ByteArrayOutputStream bo = new ByteArrayOutputStream();
                int i = is.read();
                while(i != -1) {
                    i = is.read();
                return bo.toString();
            } catch (IOException e) {
                return "";


R cannot be resolved to a variable | r-cannot-be-resolved-to-a-variable

Check your xml files in Eclipse Graphical Editor and fix problems.


Check project setup, right click on project, select properties, Java build path and
select correct Android version etc.

Right click on project, Android Tools, Fix Project Properties

Menu Eclipse select Project ->Clean.

Bitmap Canvas Color Gradient linear radial sweep rounded corner Android example | bitmap-canvas-color-gradient-linear-radial-sweep-rounded-corner-android-example

public class MainActivity extends Activity {
//  //www.apache.org/licenses/LICENSE-2.0
	protected void onCreate(Bundle savedInstanceState) {
		setContentView(new SampleView(this));

	   private static class SampleView extends View {
	        private Rect    mRect;
	        private GradientDrawable mDrawable;

	        public SampleView(Context context) {

	            mRect = new Rect(0, 0, 220, 120);
/*	            GradientDrawable.Orientation  BL_TR  draw the gradient from the bottom-left to the top-right   
	              BOTTOM_TOP  draw the gradient from the bottom to the top   
	              BR_TL  draw the gradient from the bottom-right to the top-left   
	              LEFT_RIGHT  draw the gradient from the left to the right   
	              RIGHT_LEFT  draw the gradient from the right to the left   
	              TL_BR  draw the gradient from the top-left to the bottom-right   
	              TOP_BOTTOM  draw the gradient from the top to the bottom   
	              TR_BL  draw the gradient from the top-right to the bottom-left   
	            mDrawable = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT,
	                                             new int[] { 0xFFFF0000, 0xFF00FF00,
	                                                 0xFF0000FF });
	            mDrawable.setGradientRadius((float)(Math.sqrt(2) * 60));
	        static void setCornerRadius(GradientDrawable drawable, float r0,
	                                   float r1, float r2, float r3) {
/*	        	setCornerRadii
	        	Specify radii for each of the 4 corners. For each corner, 
	        	the array contains 2 values, [X_radius, Y_radius]. 
	        	The corners are ordered top-left, top-right, bottom-right, 
	            drawable.setCornerRadii(new float[] { r0, r0, r1, r1,
	                                                  r2, r2, r3, r3 });
	        @Override protected void onDraw(Canvas canvas) {

	            float r = 35;
	            canvas.translate(10, 10);
	            setCornerRadius(mDrawable, r, r, 0, 0);
	            canvas.translate(0, mRect.height() + 10);
	            canvas.translate(10, 10);
	            setCornerRadius(mDrawable, 0, 0, r, r);
	            canvas.translate(0, mRect.height() + 10);
	            canvas.translate(10, 10);
	            setCornerRadius(mDrawable, 0, r, r, 0);


layout-sw600dp values-sw600dp Android example of use | layout-sw600dp-values-sw600dp-android-example-of-use

Why the app selects data from basic layout folder if smallest width is higher then the number in folder name?
Example 1
layout-sw600dp values-sw600dp (smallest width sw for data usage from this folder is 600dp density independent pixel!!!!!)
Device screen resolution is 1200 x 900 px (pixel) Wow, app to be select data from sw600dp folder! Realy?
DPI of device screen - dot per inch (pixel per inch) is 480 pixel it is wery important number!

  1. App selects smallest dimension of screen. In our case 900 px
    Medium screen have 160 dpi (The density-independent pixel is equivalent to one physical pixel on a 160 dpi screen, which is the baseline density assumed by the system for a "medium" density screen.).

  2. App calculate ratio 480 / 160 = 3 (The conversion of dp units to screen pixels: px = dp * (dpi / 160))

  3. App calculate smallest dimesnion of screen in dp 900 / 3 = 300 dip or dp (density independed pixel).

  4. App selects data from basic values and layout folder because sw600dp is greater than 300dp.

In our case smallest dimension of screen must be at least 1800 real - physical pixels (1800 px / 3 ratio(dpi/160) = 600 dp (dip density independend pixels) to be used data from folders values-sw600dp and layout-sw600dp.

Example 2 see Example 1 abouve
Device: Nexus 7 (2012) selected from Android Studio tool layout editor
Resolution: 800x1280 px
DPI: tvdpi (approximately 213dpi)
Ratio: 1.33 (213 / 160)
Smallest width in px: 800
Convert px to dp: 601.5 (800 / 1.33)
Result:Smallest width is 601.5dp The App to be used data from folders values-sw600dp and layout-sw600dp.

Editace: 2015-10-31 10:11:29
Počet článků v kategorii: 397

11 Share