Thursday, December 5, 2013

What to do to stop a thread in Android?

Options:

1)
if(threadOne != null) {
Thread temp = threadOne;
threadOne = null;
temp.interrupt();
}

2)
Declare threads as Daemon threads.

threadOne.setDaemon(true);
threadOne.start();

Excelent repository for Android Source Code

I recently found out an excellent repository for android source code.

http://grepcode.com

Thanks to people who took time to develop this.

Android Implicit Intent

How to login to my android device from terminal

Steps

1. sudo adb start-server

2. Check whether you are able to view your device
sudo adb devices

3. Start the shell:
sudo adb shell.

Listing all the packages installed:

pm list packages

Sunday, November 24, 2013

ArrayList printing Hashcode

When we try to print an ArrayList all at once we get

getClass().getName() + "@" + Integer.toHexString(hashCode())

In order to print the individual values, we need to change the toString() method in the class containing the setters/getters.

Add the following:

If your ArrayList is (snippets from my code):

ArrayList<Reservation> reservationsList = new ArrayList<Reservation>();
Reservation reservation;
reservation = new Reservation();
                reservation.setDescription(cursor.getString(1));

                // Does this work with recurring apps?
                reservation.setStartDate(new Date(cursor.getLong(3)));
                reservation.setEndDate(new Date(cursor.getLong(4)));
                reservation.setLocation(cursor.getString(5));
                reservationsList.add(reservation);

 //Add the overriden toString() method

@Override
    public String toString() {
        return ("Description:" + "\n" + this.getDescription() + "\n"
                + "Start Date:" + "\n" + this.getStartDate() + "\n"
                + "End Date:" + "\n" + this.getEndDate() + "\n"
                + "Location :" + "\n" + this.getLocation());
    }

Sunday, October 20, 2013

Android Accelerometer Program

Topic: Reading from android phones accelerometer and posting it in RESTful way to a URL.

Install

1)Eclipse.
2)SDK.

1. Create a new android project.
Keep all the setting to default.

Application name: AccelerometerDemo
1) Write code.

2) Check on simulator.

3)Write code for RESTful POST.

4) Correct format of the passing string or array whichever the case may be.

5) Check on real device.

6) Check when to send the post, periodically or with push of  a button.