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

Monday, March 26, 2012

Android Tip: android.view.WindowManager$BadTokenException

If you are using an ActivityGroup to display a series of activities, then you may encounter the infamous BadTokenException.

The location where you are getting the exception, will have a "this" usage for the context.

To get over this error, use "this.getParent()".

Eg:  final ProgressDialog pbarDialog = new ProgressDialog( this.getParent() );
 

Android Tip: Dealing with Droid Spinner Background

Droid seems to have an issue where in the spinner background is white and none of the elements are displayed even though they are available in the spinner.

This error has a workaround at http://stackoverflow.com/questions/4361604/how-to-change-the-spinner-font-color

Monday, July 12, 2010

Android Dev Tips

Tip 1: Import a sqlite DB from somewhere else (let us say db.sqlite)
tools$ ./adb push ~/android/db.sqlite /data/data/test.app/databases
1934 KB/s (443392 bytes in 0.223s)

Tip2:
While Activity.setContentView takes an id of a Layout, TabSpec.setContent takes an id of a View.

Tip 3: Android: Get the Application Version in an activity
PackageInfo info = getPackageManager().getPackageInfo( getPackageName(), 0 );
String version = info.versionName;

Tip 4: Android onNewIntent() is never called.

In the android manifest file for the activity, add the following attribute
android:launchMode="singleInstance"

Friday, March 05, 2010

Android Development 101

Assume you have Eclipse 3.5 installed.

Step 1: Download the Android SDK. It is usually tgz for linux.
Step 2: Install the Android plugin for eclipse.
http://developer.android.com/sdk/eclipse-adt.html

Step 3: Open Eclipse and Create a AVD (Android Virtual Device)
=========================================
To create an AVD with the AVD Manager:

1. Select Window > Android SDK and AVD Manager, or click the Android SDK and AVD Manager icon (a black device) in the Eclipse toolbar.
2. In the Virtual Devices panel, you'll see a list of existing AVDs. Click New to create a new AVD.
3. Fill in the details for the AVD.
Give it a name, a platform target, an SD card image (optional), and a skin (HVGA is default).
4. Click Create AVD.
================================

Step 4: Now create a new Android project. File -> New -> Android - >Android Project. Choose a target.


Testing on your phone :-
Best is to have the Android Development Phone 2 (ADP2).

Then to debug your application from Eclipse onto the phone.
1) Set up your ADP2 or your device to USB connect with your computer.
2) Make your application "debuggable". You need to do this in the android manifest.
3) Eclipe Run -> Run As -> Android Application


Note: To set up ADP2 on Fedora/Ubuntu, do the following:

$> sudo vi /etc/udev/rules.d/51-android.rules.
UBSYSTEM=="usb", SYSFS{idVendor}=="0bb4", MODE="0666"

$> $ sudo chmod a+r /etc/udev/rules.d/51-android.rules.