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


AD MOB

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();
}			

397LW NO topic_id




AD

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


145

Compressing converting a bitmap to PNG format Android example | compressing-converting-a-bitmap-to-png-format-android-example



public class MainActivity extends Activity {
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(new SampleView(this));
	}

	private static Bitmap codec(Bitmap src, Bitmap.CompressFormat format,
			int quality) {
		ByteArrayOutputStream os = new ByteArrayOutputStream();
		src.compress(format, quality, os);

		byte[] array = os.toByteArray();
		return BitmapFactory.decodeByteArray(array, 0, array.length);
	}

	private static class SampleView extends View {

		// CONSTRUCTOR
		public SampleView(Context context) {
			super(context);
			setFocusable(true);

		}
		@Override
		protected void onDraw(Canvas canvas) {
			Paint paint = new Paint();
			
			canvas.drawColor(Color.YELLOW);
            
        
			Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.flower_blue);
             
			Bitmap bPNGcompress = codec(bmp, Bitmap.CompressFormat.PNG, 0);

		   int h = bmp.getHeight();
           
           canvas.drawBitmap(bmp, 10,10, paint);
           canvas.drawBitmap(bPNGcompress, 10,10 + h + 10, paint);
           
		}

	}
}

124

Resource int R.string.app_name to String Android example | resource-int-r-string-app_name-to-string-android-example


R.string.app_name to String example.
MyActivity.java

Resources res = getResources();
String sText = res.getString(R.string.app_name);


res/values/string.xml


<resources>
    <string name="app_name">My app name</string>
</resources>

179

Samsung Galaxy S | samsung-galaxy-s


Samsung Galaxy S nejlepší cena od 4 500 KCZ Kč (únor.2012)
Samsung Galaxy S je chytrý telefon s operačním systémem Android.
Samsung Galaxy S je (22.února2012) 5. a 6. nejpoužívanějším chytrým telefonem u programu Sky Map viz tabulka.


Samsung Galaxy S byl představen firmou Samsung v březnu 2010. Je vybaven 1 GHz ARM "Hummingbird - kolibřík" procesorem, 8-16 GB interní flash pamětí, 4-palcovým 480 × 800 pixelů Super AMOLED kapacitním dotykovým displejem, Wi-Fi připojením, 5-megapixelovým fotoaparátem s maximálním rozlišením 2560x1920 a u vybraných modelů předním čelním 0,3 MP fotoaparátem VGA (640x480).

Samsung Galaxy S photo pic image
samsung galaxy s2
Zdroj obrázku: wikipedia
330

Android Studio reduce memory usage of PC | android-studio-reduce-memory-usage


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.
362

Android Studio gradle file comment same as java comment | android-studio-gradle-file-comment-same-as-java-comment



// single line
/*
multi line
*/


Editace: 2011-10-03 11:09:06
Počet článků v kategorii: 397
Url:write-file-java-android-example

AD
11 Share
Share
Tweet