Showing posts with label android. Show all posts
Showing posts with label android. Show all posts

Wednesday, October 24, 2012

How to stop Android Monkey UI exerciser

Started monkey test but wish to stop it now?
Find the process with a question mark as shown above. That is most likely the monkey process.
Just kill it!

Saturday, January 28, 2012

Keep Screen On!

Sometimes you just want to keep the screen light on while the user is on a certain Activity.
Enter.. FLAG_KEEP_SCREEN_ON!

FLAG_KEEP_SCREEN_ON - "Window flag: as long as this window is visible to the user, keep the device's screen turned on and bright. "



Usage: 
A. Inside the onCreate() method of your Activity
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

or

B. In your layout xml
<RelativeLayout... android:keepScreenOn="true" />

As long as this Activity is shown to the user, the screen light will be on! Once the user moves over to another activity, the default screen timeout will kick-in.
No wake lock required!

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.