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.

Write new file or append text Java Android example

BufferedWriter, FileWriter, write, close MODE_APPEND Java and Android example

Write to file Android example

try {
		String MYFILE = "my_file";
		String strText = "My text";

                // MODE_APPEND, MODE_WORLD_READABLE, MODE_WORLD_WRITEABLE
		// create new file or rewrite existing
                FileOutputStream fos = openFileOutput(MYFILE, getApplicationContext().MODE_PRIVATE);
                // append to file
                FileOutputStream fos = openFileOutput(MYFILE, getApplicationContext().MODE_APPEND);

		fos.write(strText.getBytes());
		fos.close();					
	} catch (IOException e) {
		e.toString();
    }	




Write to file Java example

try {
// new file    
BufferedWriter out = new BufferedWriter(
    		new FileWriter("outfilename"));
    // append text 
   BufferedWriter out = new BufferedWriter(new FileWriter("outfilename", true));
    out.write("some text");
    out.close();
 } catch (IOException e) {
   e.toString();
}			

396LW NO topic_id




AD

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


388

Expected resource of type raw drawable | expected-resource-of-type-raw-drawable


Try insert + before R.drawable.xxxx

// error
InputStream is = context.getResources().openRawResource(R.drawable.app_sample_code);

// ok
InputStream is = context.getResources().openRawResource(+R.drawable.app_sample_code);

356

Saving Activity state int String Array Double on Android | saving-activity-state-int-string-array-double-on-android



private int[] mData = new int[2]; // fill some values into array!!
 @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putBoolean("myBoolean", true);
        outState.putDouble("myDouble", 2.7);
        outState.putInt("myInt", 5);
        outState.putString("myString", "Heloo girls!");
       int[] data = new int[mData.length];
        for (int i = 0; i < data.length; i++) {
            data[i] = mData[i];
        }
        outState.putIntArray("myArray", data);

    }
@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
  super.onRestoreInstanceState(savedInstanceState);
  boolean myBoolean = savedInstanceState.getBoolean("myBoolean", false); // false basic value
  double myDouble = savedInstanceState.getDouble("myDouble", 1.5); // 1.5 basic value
  int myInt = savedInstanceState.getInt("myInt", 10);
  String myString = savedInstanceState.getString("myString", "Hello boys!");
  int[] data = savedInstanceState.getIntArray("myArray");
  
  if (data != null && data.length == mData.length) {
            for (int i = 0; i < data.length; i++) {
                mData[i] = data[i];
            }
        }
}
@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  boolean myBoolean =  savedInstanceState != null ? savedInstanceState.getBoolean("myBoolean", false) : true;
// etc.  .......
}

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]
*/


120

Statistics usability of mobile phones with Android – October 2011 | statistics-usability-of-mobile-phones-with-android-%e2%80%93-october-2011


Table of usability phones with Android: (Our software)












October 2011 September 2011












Samsung Galaxy S2 10,90%
Samsung Galaxy S 8,10%
Samsung Galaxy Tab 7,00%
Samsung Galaxy Mini 6,20%
HTC Desire HD 4,10%
Samsung Galaxy Ace 4,10%
Samsung Galaxy S 4,00%
Samsung Galaxy Fit 3,30%
HTC Wildfire 3,20%
SEMC Xperia X10 2,20%

























Samsung Galaxy S213.8%
Samsung Galaxy S8.5%
Samsung Galaxy Tab7.4%
Samsung Galaxy Mini5.4%
Samsung Galaxy S4.0%
HTC Desire HD3.8%
Samsung Galaxy Ace3.8%
HTC Wildfire3.2%
Samsung Galaxy Fit3.1%
SEMC Xperia X102.1%



Graph of usability Smartphone with Android - October 2011:
android/phones-usability-wiht-android-october-2011.png


Samsung Galaxy S2 vs iPhone4 - video


Samsung Galaxy S2 vs iPhone4 - browsing, gaming, apps, performance, browser, fast, against, navigation, Sygic, apk, Android, iOS