Friday, November 4, 2011

Easy way to install an apk on Windows

If you are a developer, you would frequently generate an apk on a remote machine and copy to your Windows PC and then install it on your phone. Or an apk sent by your team member.
Here is a quick and convenient way to install the apk on your phone with a double-click!

1. Copy the below code to a text file, and rename it install_apk.bat. Save the .bat file somewhere on PC
adb install -r %1
PAUSE

(if you adb.exe is not on classpath, you can also specify the complete path to the exe. Ex C:\android-sdk-windows\platform-tools\adb.exe)

2. In windows explorer, select your apk -> Right click -> Open With -> Choose Program -> Browse -> Select the above .bat file
Also, check "Always use selected program..." option.
Click OK

Thats it, now you can install any apk with a double click (provided a device is connected to the PC via usb)

The Simplest List View!


Android has a built-in layout android.R.layout.simple_list_item_1

But how do you really take advantage of this, without creating a separate XML of your own?

Here is how I did it...

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       
        List<String> data = new ArrayList<String>();
        data.add("King");
        data.add("Queen");
        data.add("Bishop");
        data.add("Rook");
       
        ArrayAdapter arrayAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, data );
        setListAdapter(arrayAdapter);
       
        getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {

            public void onItemClick(AdapterView<?> parent, View view, int position,
                    long arg3) {
                //item clicked
            }
        });
    }




---------------------
No setContentView, no separate XML required!


Thats all!! Trust me.