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.

Do not hardcode /data/ use Context.getFilesDir().getPath()


// warning
private static String DB_PATH =  "/data/data/cz.okhelp.german_czech_phrases/databases/";

// OK
   public DataBaseHelper(Context context) {	 
    	super(context, DB_NAME, null, 1);
        this.myContext = context;
        // OK
         DB_PATH = context.getFilesDir().getParentFile().getPath()
              + "/databases/";

397LW NO topic_id


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


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.

File open read to StringBuilder close Java example | file-open-read-to-stringbuilder-close-java-example

BufferedReader , FileReader, StringBuilder , readLine, close Java example

Android example

String MYFILE = "my_file";
FileInputStream fis = openFileInput(MYFILE);
	int c; String sText = "";

		sText += (char)c; // convert int to char

Java example

try {
	    BufferedReader in = new BufferedReader(new FileReader("myfile.txt"));
	    StringBuilder strBuilder = new StringBuilder();
	    String str;
	    while ((str = in.readLine()) != null) {
	} catch (IOException e) {


onSaveInstanceState() onRestoreInstanceState() basic Android example | onsaveinstancestate-onrestoreinstancestate-basic-android-example

public class MyClass extends Activity {
    public void onCreate(Bundle savedInstanceState) {
	 String sMyText = "some text";
	 int nMyInt = 10;

 protected void onSaveInstanceState(Bundle outState) {
     // Save away the original text, so we still have it if the activity
     // needs to be killed while paused.
     outState.putString("my_text", sMyText);
     outState.putInt("my_int", nMyInt);
     Toast.makeText(this, "onSaveInstanceState()", Toast.LENGTH_LONG).show();
Log.i("onSaveInstanceState", "onSaveInstanceState()");
 String sNewMyText = "";
 int nNewMyInt = 0;
 protected void onRestoreInstanceState(Bundle savedInstanceState) {
     // restore saved values
     sNewMyText = savedInstanceState.getString("my_text");
     nNewMyInt = savedInstanceState.getInt("my_int");
     Toast.makeText(this, "onRestoreInstanceState()", Toast.LENGTH_LONG).show();
     Log.i("onRestoreInstanceState", "onRestoreInstanceState()");

Whittled superscript sup tag TextView Android issue | whittled-superscript-sup-tag-textview-android-issue

Issue: Cropped superscript index between tags sup /sup is not correctly visible in TextView or View as Button.

String s = "10<sup>12 </sup>";
textView.setText(Html.fromHtml(s)); // 12 will cropped 
// solution:
s = "10<sup>12 </sup>\t	"; // add behind ending of sup tag the tabulator \t, 
// but not char \t but only press to TAB key!!! in source code
textView.setText(Html.fromHtml(s)); // 12 is visible correctly


Eclipse - Workspace in use or cannot be created chose a different one | eclipse-workspace-in-use-or-cannot-be-created-chose-a-different-one

Open your workspace folder and subfolder .metadata:

Delete .lock file

Editace: 2013-12-12 14:09:55
Počet článků v kategorii: 397

11 Share