Sunday, December 29, 2013

Eclipse doesn't render layout


After installing the new Android SDK, the graphical layout in Eclipse is blank.. It shows

This version of the rendering library is more recent than your version of ADT plug-in. Please update ADT plug-in.

If you get this message, it means that your ADT is out of date and needs to be updated. Follow the below steps to update it,

  1. Click Help > Install New Software.
  2. In the Work with field, enter: https://dl-ssl.google.com/android/eclipse/
  3. Select Developer Tools / Android Development Tools.
  4. Click Next and complete the wizard.

Tuesday, October 22, 2013

Preventing Android device from going to sleep - programmatically?


To prevent an Android device from going to sleep programmatically,

Call setKeepScreenOn(true) on that View or set the keepScreenOn property to true. This will prevent the screen from going off while the View is on the screen. No special permission required for this.

Sunday, October 20, 2013

Margin vs Padding - difference??


Knowing the difference between margins and padding in Android is quite important.

Padding is the space inside the border, between the border and the actual view's content. Note that padding goes completely around the content: there is padding on the top, bottom, right and left sides (which can be independent).
Basically this is relative to your border, if you want to add the space between the elements inside the border (i.e. have the borders touching), you should use the padding property.

Margins are the spaces outside the border, between the border and the other elements next to this view. In the image, the margin is the grey area outside the entire object. Note that, like the padding, the margin goes completely around the content: there are margins on the top, bottom, right, and left sides.
If you want to add the space outside the borders (have the borders apart) you should use the margin property.
An image says more than 1000 words:
alt text 

Saturday, August 17, 2013

ClassCastException in FrameLayout - changing


I'd spent quite a lot of time to find out the root cause of ClasscastException when we change the order of views in layout xml..

And found that if we do "Project --> Clean" in Eclipse the problem will be resolved.

Eclipse - is the culprit :)

Tuesday, July 9, 2013

Admob error in Eclipse? - Android


Eclipse is showing an error in android:configChanges line in my AndroidManifest.xml:

<activity android:name="com.google.ads.AdActivity"
              android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"></activity>
and the error is,
error: Error: String types not allowed (at 'configChanges' with value 'keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize').

I resolved it by setting target=android-13 in project.properties file.. After changing it don't forget to do Project-> Clean 

If you would like to know how to make use of Admob in your Android app, you can take a look at this tutorial..

http://www.monkeycoder.co.nz/Community/posts.php?topic=1121

APK signed with a certificate that is not yet valid - Android?

While publishing the app I got the below error,

"You uploaded an APK signed with a certificate that is not yet valid. You need to sign your APK with a certificate that is currently valid."

After several Google searches, I resolved this issue by changing the system date of the computer.. I changed my system date to some earlier date, generated a new keystore and uploaded the app.. it worked like a charm :)


Tuesday, July 2, 2013

How to start an activity if the user clicks on OK button in AlertDialog - Android?

Make use of this code to start an activity if the user clicks on OK button in AlertDialog,

AlertDialog.Builder alertDialog = new AlertDialog.Builder(Someclass.this);
    builder.setMessage("Are you sure you want to quit?")    alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {  
    public void onClick(DialogInterface dialog, int which) { 
        Intent myIntent = new Intent(((Dialog) dialog).getContext(), Someclass2.class);        startActivity(myIntent);    
        return;  
        }        
    })
    .setNegativeButton("Cancel", new DialogInterface.OnClickListener(){
        public void onClick(DialogInterface dialog, int which) {
             // Do Nothing
     }

    alertDialog.show();