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.

Get Bitmap Size Get Free Memory Exception Android



Bitmap size calculation:
bmpHeight * bmpWidth
For example:
Resolution of image 1024x860 = 880 640 pixels
If every pixel get 4 byte of memory:
880 640x4= 3 522 560 (3.5MB)

Get bitmap size without allocation of memory:

   	BitmapFactory.Options options = new BitmapFactory.Options();
        // If set to true, the decoder will return null (no bitmap), but the out... fields will still
        // be set, allowing the caller to query the bitmap without having to allocate the memory for its pixels. 
    	options.inJustDecodeBounds = true; 
    	BitmapFactory.decodeResource(getResources(), R.drawable.my_image, options);
    	int imageHeight = options.outHeight; // 1024
    	int imageWidth = options.outWidth; // 860
    	String imageType = options.outMimeType; // .jpg .png .gif
 


Get Memory size:
Make your bitmap not bigger as maxMemory size
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);

    float density = getResources().getDisplayMetrics().density;

    Debug.MemoryInfo memoryInfo = new Debug.MemoryInfo();
    Debug.getMemoryInfo(memoryInfo);
    final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
    final int freeMemory = (int) (Runtime.getRuntime().freeMemory() / 1024);
    String memMessage = String.format(
        "Free=%d kB,

MaxMem=%d kB,
Memory: Pss=%.2f MB, Private=%.2f MB, Shared=%.2f MB", freeMemory, maxMemory, memoryInfo.getTotalPss() / 1024.0, memoryInfo.getTotalPrivateDirty() / 1024.0, memoryInfo.getTotalSharedDirty() / 1024.0); ((TextView)findViewById(R.id.textViewInfo)).setText(memMessage );

397LW NO topic_id



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


270

setTesting(boolean) from the type AdRequest is deprecated | settestingboolean-from-the-type-adrequest-is-deprecated


Admob testing on emulator issue.
Android Eclipse code warning:
setTesting(boolean) from the type AdRequest is deprecated
Solution:
adRequest.addTestDevice(AdRequest.TEST_EMULATOR);


AdView adView = new AdView(this, AdSize.BANNER, "a14d9..........");//MY_AD_UNIT_ID
AdRequest adRequest = new AdRequest();
		adRequest.setTesting(true); // deprecated

		adRequest.addTestDevice(AdRequest.TEST_EMULATOR); // OK
		adView.loadAd(adRequest);

45

Adding TableRow add row with a View TextView dynamically to TableLayout Android sample example | adding-tablerow-add-row-with-a-view-textview-dynamically-to-tablelayout-android-sample-example


Adding TableRow with a View TextView (EditText Button) programmically dynamically to TableLayout Android sample basic example.
MainClass.java

public class MainClass extends Activity {
   
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        TableLayout tl = (TableLayout)findViewById(R.id.tableLayout1);
        TableRow row = new TableRow(this);
        TextView tv = new TextView(this);
        tv.setText("This is text");

        tl.addView(row);
        row.addView(tv);

    }
}



main.xml

<?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"
    >
<TableLayout android:layout_width="fill_parent" 
    android:id="@+id/tableLayout1" android:layout_height="wrap_content">
</TableLayout>
</LinearLayout>

258

Save Restore Array List Android Example | save-restore-array-list-android-example



        int[] mArrayOfInt;
        String[] mArrayOfString;
        List<String> mList;
        public void saveState(Bundle map)
        {
                map.putIntArray("mArrayOfInt", mArrayOfInt);
                map.putStringArray("mArrayOfString", mArrayOfString);
                map.putStringArrayList("mList", mList);
        }

        public void restoreState(Bundle map)
        {
                mArrayOfInt= map.getIntArray("mArrayOfInt");
                mArrayOfString = map.getStringArray("mArrayOfString");
                mList = map.getStringArrayList("mList");

        }

0

EditText text changed java Android | edittext-text-changed


Google Android example source code - is text changed in EditText ?

EditText hEditText;

// TextChanged in onCreate
hEditText = (EditText)findViewById(R.id.idEditText);
hEditText.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable str) {
}

public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}

public void onTextChanged(CharSequence sq, int start, int before,
int count) {
}
});
81

Shuffle List ArrayList Collections Java example | shuffle-list-arraylist-collections-java-example


Add and shuffle elements in LinkedList or ArrayList Java basic example.


import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

public class MainClass {
	public static void main(String[] arg) {
		String[] arrayOfString = {"nothing", "Hello", "people"
				, "bye-bye", "hello", "world!", "End" };
		   List<String> arrayList = new LinkedList<String>();
            for(String s: arrayOfString)
		     arrayList.add(s);

		    Collections.shuffle(arrayList);

		    System.out.println(arrayList);
		    
		  }
}
/*
[hello, world!, bye-bye, nothing, people, End, Hello]
*/




Editace Jana Žákovská : 2013-12-09 12:58:29
Počet článků v kategorii: 397
Url:get-bitmap-size-get-free-memory-exception-android
Share
Share
Tweet