BadTokenException Error In Android Dialog

If you are creating a custom Dialog for Android, and following the Android Developers’ Creating Dialogs tutorial, then most likely you would have faced a Force Close with this exception showing up in logcat. I did too. Although I figured it out quickly, it might not be easy to find out for many, so posting it here for reference. Basically, the code given in the tutorial goes something like this:

Context mContext = getApplicationContext();       
Dialog dialog = new Dialog(mContext); 
dialog.setContentView(R.layout.custom_dialog);       
dialog.setTitle("Custom Dialog"); 
TextView text = (TextView) dialog.findViewById(R.id.text);       
text.setText("Hello, this is a custom dialog!");        
ImageView image = (ImageView) dialog.findViewById(R.id.image);        
image.setImageResource(R.drawable.android);

All looks well, but when you execute it, you will get a Force Close. The error appearing in logcat would be something like this:

Android App: Wi-Fi Keep Alive Updated to 1.2.0

Just finished uploading the new version 1.2.0 of my android app Wi-Fi Keep Alive to the Android market. This version has a lot of optimizations and also a few workarounds to overcome the issues few guys were facing with Android’s in-built handling of wi-fi sleep policies.

Changes done in this version:

  • Added workarounds to take care of sleep policies not working on some phones

  • Optimized the code a bit for faster operations

Android App: Wi-Fi Keep Alive

I just wrote my second Android App. This again was to scratch an itch of mine but it seems to have become a bit popular already (My first app “Quick Sync Settings” did around 400 downloads in 20 days but this one has already surpassed that in less than one day). This app basically allows you to change the wi-fi sleep policy on android so that you can keep your wi-fi connected even if the phone goes to sleep (i.e. screen turns off). What’s more is that I’ve added a widget to it so you don’t even have to go into the app. Just tap on the widget to cycle through the settings.

Wi-Fi Keep Alive

UPDATE Potential work arounds for folks having problem in sleep policies not working correctly have been put in version 1.2.0 onwards. Please redownload to test and let me know. Read below for more details.

Latest Version: 1.4.4 (See below for change log history)

Are you frustrated by your downloads getting broken or worse, switching over to slow and expensive mobile data connections like GPRS/Edge/3G when your wi-fi connection gets dropped by your Android phone when the screen goes off? If yes, then look no further. Here is my app that allows you to choose your desired Wi-Fi Sleep policy. You can choose from the following options:

Android vs iPhone: Security Models

Android and iPhone OS (iOS) have been at loggerheads for quite some time now. This is a take on which has a better security model to protect its users. I thought of writing it up because there have been a lot of discussions around me lately about which platform is more secure and I keep repeating the same points over and over at every one of them, so thought that in future I’ll just point them to this page :P