Effect of frequent sdcard writes

In my chat app, I am adding the ability to log chats. The logs are saved on the sdcard and one BufferedWriter is kept open for every person/channel chat is done with. I’m wondering what effects this might have have on the sdcard and its life.

My BufferedWriter‘s buffer size is to 1024, I’m also wondering if that is too small or too big.


Flash memory cards have an endurance of about a million write cycles per area and probably include wear levelling which basically means trying to write to different areas so specific spots dont wear out.

So after about (sizeOfSDCard/sizeOfYourData)*1,000,000 writes, you will have ruined their card.

Practically, this means you probably aren’t going to cause any harm.


BindException with INTERNET permission requested

I have seen several questions regarding SocketException when using Android, but none of them cover the BindException that I get even with the INTERNET permission specified in my manifest.

Here is part of my manifest:

<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>

<uses-permission android:name="android.permission.READ_OWNER_DATA"></uses-permission>
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>

<uses-permission android:name="android.permission.ACCOUNT_MANAGER"></uses-permission>
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS"></uses-permission>

Here is the relevant portion of my LogCat output:

04-22 14:49:06.117: DEBUG/MyLibrary(4844): Address to bind: port: 843
04-22 14:49:06.197: WARN/System.err(4844): Permission denied (maybe missing INTERNET permission)
04-22 14:49:06.207: WARN/System.err(4844):     at org.apache.harmony.luni.platform.OSNetworkSystem.socketBindImpl(Native Method)
04-22 14:49:06.207: WARN/System.err(4844):     at org.apache.harmony.luni.platform.OSNetworkSystem.bind(
04-22 14:49:06.217: WARN/System.err(4844):     at
04-22 14:49:06.217: WARN/System.err(4844):     at
04-22 14:49:06.227: WARN/System.err(4844):     at org.apache.harmony.nio.internal.ServerSocketChannelImpl$ServerSocketAdapter.bind(
04-22 14:49:06.227: WARN/System.err(4844):     at
04-22 14:49:06.237: WARN/System.err(4844):     at org.apache.harmony.nio.internal.ServerSocketChannelImpl$ServerSocketAdapter.bind(
04-22 14:49:06.237: WARN/System.err(4844):     at$PolicyServerWorker.(

I Really hope this is a simple problem and not something complicated by the fact that the binding is occurring within a worker thread on a port less than 1024.


Looks as if this is a privileged port issue, anyone know how to bind to ports lower than 1024 in Android?

    SelectorProvider provider = SelectorProvider.provider();
    try {
        ServerSocketChannel channel = provider.openServerSocketChannel();
        policySocket = channel.socket();
        Log.d("MyLibrary", "Address to bind: " + device.getAddress().getAddress() + " port: 843");              
        InetSocketAddress addr = new InetSocketAddress(InetAddress.getByName(device.getAddress().getAddress()), 843);
    } catch (Exception e) {


anyone know how to bind to ports lower than 1024 in Android?

Either root your phone, modify the firmware, or don’t bind to ports lower than 1024. That’s a Linux thing more than an Android thing.


How does volatile actually work?

Marking a variable as volatile in Java ensures that every thread sees the value that was last written to it instead of some stale value. I was wondering how this is actually achieved. Does the JVM emit special instructions that flush the CPU cashes or something?


From what I understand it always appears as if the cache has been flushed after write, and always appears as if reads are conducted straight from memory on read. The effect is that a Thread will always see the results of writes from another Thread and (according to the Java Memory Model) never a cached value. The actual implementation and CPU instructions will vary from one architecture to another however.

It doesn’t guarantee correctness if you increment the variable in more than one thread, or check its value and take some action since obviously there is no actual synchronization. You can generally only guarantee correct execution if there is only just Thread writing to the variable and others are all reading.

Also note that a 64 bit NON-volatile variable can be read/written as two 32 bit variables, so the 32 bit variables are atomic on write but the 64 bit ones aren’t. One half can be written before another – so the value read could be nether the old or the new value.

This is quite a helpful page from my bookmarks:


Can I move another program’s window to the front of focus?

I am interacting with a third party application using it’s API, and would like to move it to the front of focus (so that it is on top of all other open windows) when a user performs a certain action. While I can move my application up and down in the hierarchy pretty easily, there doesn’t appear to be a way to interact with other windows. Is it possible to move another program’s window to front with Java?


You can’t do it in pure Java code, but you could using JNI. See In Java Swing how do you get a Win32 window handle (hwnd) reference to a window? for how to get a handle to the window. Then you could do something like to move it to the front.

Caveat: This is for windows only


Android ADT Eclipse plugin, parseSDKContent failed

I’ve just set up my first Android development environment consisting of

  • Eclipse 3.5
  • Mac OSX 10.5
  • Android SDK for x86 macs
  • ADT Eclipse plugin 0.9.6

I’ve set set $PATH to my SDK/tools directory (which shouldn’t matter if I only use Eclipse right?) and started Eclipse, but when I try to set the path to the SDK in Eclipse, i get the error “parseSdkContent failed”. The stack trace of from the thrown exception is

at javax.xml.validation.SchemaFactory.newInstance(
at Source)
at Source)
at Source)
at Source)
at<init>(Unknown Source)
at Source)
at$ Source)

I can’t see that I’ve missed anything in the setup process, according to the instructions it should basically just work out of the box. Any ideas as to why this might fail?


A quick glance at suggests that something is wrong with the JDK 1.6 setup.

Setting the -vm flag in eclipse to the original 1.5 did not help, but after removing all traces of the apparently misconfigured 1.6 everything worked like a charm.

Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..