20 Nov 2012

Use adb wifi without rooting for Android phones

Well, if your phone is rooted already, it's very easy to use adb without USB cables. Just go to Google Play then search for "adb wifi", you'll see several apps which can help you with your rooted phone.
But if for some reasons, you don't want or mustn't root your phone (because of the warranty or the phone is not yours...), and you hate debugging your app with the cable plugged in your phone, well, there's still a workaround for you (but it still requires to use the USB cable once or twice)

  • Connect your Android phone with your  computer by the USB cable, and make sure you have adb and required drivers for you phone installed on your computer. Then type (this command tells adb daemon to listen over Wifi - port 5555):
  • adb tcpip 5555
  • Okay, now you can plug out your USB cable and throw it away (just kidding, you'll might need it in case you restart your phone or you pull out the battery...). Now you have to find your phone IP, go to Setting -> Wi-Fi -> Select the Wi-Fi network your phone is using, then you'll see the IP address. Now on your computer, you have to connect adb to your phone, for example, IP address of my phone is, I'll do it by this command:
  • adb connect
  • Then you'll see message "connected to", now your phone is connected to adb wirelessly. If you want to use adb over USB again, connect your phone to your computer then type in cmd or Terminal:
  • adb usb

That's all, good luck!

17 Nov 2012

A note about .gitignore

First of all, take a look at this page:
And I'm not copying its content lol, well, this is just a note about what I've done successfully with .gitignore to ignore some folders in my project.

  • Enter to root directory of your project, then "vi .gitignore" and enter something like:(I suppose you haven't had .gitignore in your project):
  • bin/ # ignore all folders which are named "bin"
    .settings/ # ignore all folders which are named ".settings" 

  • If there's nothing in your "bin" folders as well as ".settings" folders, your job here is done, everything you will put in those folders will not be tracked by Git. But if there's something in those folders which means Git are tracking it already, so you have to let Git know that you don't want to tracking it by these commands:
  • git rm --cached -r Your_Path/bin/
    git rm --cached -r Your_Path/.settings/
    git commit -m "Ignore folder bin and .settings"
    git push origin your_branch

P/S: You may doubt about removing cache then commit & push, and yeah, I did, but don't worry. Doing so just removes cache not actual files in your folders (actually I have no idea about where is cache too, but I guess it's cache of git lol), and committing & pushing just delete those folders on remote server, not on your local repository.
In short, making a ".gitignore" just tells your Git program on your computer knows that don't list changes of files in those folders when you type "git status",  and removing cache & committing & pushing just delete those folders on remote repository.

How to install and config Smartgit + Git +

  • Download install Git:
  • Download install SmartGit:
  • Add SSH public key:
    • Generate SSH public key if it hasn't been created
      • Open Git Bash -> Generate SSH public key by typing: ssh-keygen -t rsa -C "" -> Public key will be located in folder "~/.ssh/"
    •  Add SSH public key to
      • Open -> Account setting -> SSH keys -> Add Key -> Add content of "~/.ssh/" as a key
  • In order to be able to push, you have to config your name and email, open Git Bash, type:
    • git config --global ""
    • git config --global "Blah Bloh"
  • Clone a project (choose SSH, don't choose HTTPS, otherwise you will not be able to push properly by SmartGit - Actually, I don't know why, it took me a few hours to realize that, but I still can't explain why now lol):
    • git clone
  • Add project to Smartgit:
    • Project -> Open Repository -> Choose your project folder -> Next...

6 Nov 2012

Synchronized keyword in Java

2 effects:
  • First, it is not possible for two invocations of synchronized methods on the same object to interleave. When one thread is executing a synchronized method for an object, all other threads that invoke synchronized methods for the same object block (suspend execution) until the first thread is done with the object.
  • Second, when a synchronized method exits, it automatically establishes a happens-before relationship with any subsequent invocation of a synchronized method for the same object. This guarantees that changes to the state of the object are visible to all threads.

Explanation about lock object of synchronized block:
  • If you synchonize on the method ( as you're doing by typing public synchronized void addA() ) you lock the whole object, so two thread accessing a different variable from this same object would block each other anyway.
  • If you want to syncrhonize only a variable at a time , so two thread wont block each other while accessing different variables, you have to add them in a synchronized block, and use the variable as the "lock" of the block. If a and b were object references you would use:
public void addA() {
    synchronized( a ) {
public void addB() {
    synchronized( b ) {