Thursday 28 April 2011

Why to choice android not iPhone or Other Phone Here the 10 Reasons


10 Things Android Does Better Than iPhone OS

When Android first debuted on the HTC Dream (also known as the G1) back in October of 2008, it was deemed an "iPhone Killer." While it didn't quite slay Apple's handset, it was the first step in a revolution against the tyrannous iPhone. The initial Android platform bested the iPhone OS on several levels, but lacked some key functionalities that the iPhone could provide. Since then, Android has grown - not only meeting all of the functionalities of the iPhone, but besting it in nearly all aspects from an extensive list of devices to a growing Android Marketplace. Here is our list of the top 10 things Android does better than the iPhone.

1: Android can Run Multiple Apps at the Same Time


Starting with version 1.0, Android has been able to run multiple applications at the same time regardless of whether they are system apps or apps from the Android Marketplace. The current version of iPhone OS does offer limited multitasking, but only allows native applications such as Mail, iPod and Phone to run in the background. Android users benefit greatly from this discrepancy, as they can receive notifications, listen to music, or even record GPS data without keeping the application open. Apple will try to level the playing field with iPhone OS 4, granting developers access to a small and limiting list of APIs that can run certain services in the background, but it's a long way from the true multitasking that Android has.

2:  Android Keeps Information Visible on Your Home Screen


One of the key features Android has is a customizable home screen keeps active widgets right at your fingertips, always accesible and always visible - without having to launch an application first. There are widgets for just about every app in the Android Marketplace from playing music to checking the weather and keeping up to date on Facebook. Meanwhile iPhone users are force to flip through their app list to locate and launch each app. If you wanted to check the forecast, for example, you would have to find the app, launch it, and then wait for it to load. With Android, all of that information can be displayed directly on your home screen, never more than a finger swipe away.


3: Android Has a Better App Market


It's true that Apple's App Store has over 180,000 applications, while the Android Marketplace has only just broken the 50,000 mark but Android's rapid growth and adoption give it the potential to catch up to the iPhone App Store. Android also has another advantage: a completely open market. Apple receives around 10,000 app submissions per week, yet many apps are overlooked because they appear too simple or denied because a similar app already exists. The Android Marketplace is driven entirely by its consumers, so the best app is the one that succeeds - not the first one to reach the market. In addition, the Android Marketplace doesn't censor its apps, so the possibilities are truly endless.

4: Android Gives You Better Notifications 


The iPhone has some trouble with notifications. Because it's restricted to pop-up notifications, it can only handle one at a time and because it lacks multitasking, applications must be open in order for them to make notifications. Android, on the other hand, has a convenient notification bar which displays an icon for every notification you have waiting. The notification bar can also be pulled downward to reveal more detail about each notification. Android also allows app developers to make notification details viewable from the lock screen, something the iPhone can only do with native applications.

5: Android Lets You Choose Your Hardware 


Apple users are encouraged to "Think Different" but when it comes to the actual hardware, they don't get much choice. You can pick the color, either black or white, and you get to choose between the 16GB or the pricier 32GB version. Other than that, you're stuck with the 3.5-inch, 320x480 pixel display, 256MB of RAM, and 600MHz processor. Because Android is an open platform, manufacturers have the freedom to pair it with any hardware they want, like the Nexus One (with 3.7-inch, 480x800 pixel display, 512MB of RAM, and 1GHz Snapdragon processor) or the Motorola Droid which has a physical keypad. Obviously, available selections will vary by carrier - speaking of which....

6: Android Lets You Choose Your Carrier

AT&T truly is the iPhone's weakest link. The iPhone's success turned the country's fastest 3G network into a staggering mess of dropped calls and dodgy data connections. If you lust after an iPhone and live in an area with poor AT&T coverage, you're stuck struggling with low signal quality, slow data speeds, and missed calls. Android devices are available on every major cellular carrier (although AT&T only offers a single, somewhat underpowered, Android phone). Verizon has the Motorola Droid, Droid Eris, and Droid Incredible to start. T-Mobile has the Nexus One, MyTouch 3G, Behold II, and will soon carry the MyTouch Slide. And Sprint has the Hero, Moment, and plans for the very promising Evo 4G. No matter where you live, Android lets you pick the carrier that's best for you.

7: Android Lets You Install Custom ROMs

The iPhone can be Jailbroken for some additional functionality, like installing apps that aren't available in the App Store, but the overall experience is the same. You're still stuck with the same exact interface. Similar to the Jailbreaking movement, Android has a small community dedicated to building custom ROMs for Android devices. Not only do Custom ROMs bring the same functionality Jailbreaking does, but they also bring an additional level of customization to your phone. There are ROMs that port custom UIs from one device to another. Other ROMs strip down bulky features and optimize for speed. With Android, nothing is out of reach.

8: Android Lets You Change Your Settings Faster

Smartphones have been gaining more and more functionality over the past few years: Wi-Fi, GPS, 4G, Bluetooth, etc. While these are all great and necessary additions, they have very adverse affects on battery life. In attempts to counter poor battery life, users have taken to toggling system settings like turning on Wi-Fi or 3G on only when they are needed. iPhone users are stuck digging around in the system settings every time they want to use the internet or a Bluetooth device. Android lets you use widgets to manage your settings directly from your home screen - and for those lesser-used settings that might not have dedicated widgets, you can also create shortcuts on your home screen to take you directly to the setting you want to change.

9: Android Does Google and Social Integration

With Smartphones giving us constant connectivity, it's not surprising that the majority of our computerized lives are moving online. We have email for our messages, Flickr for our photos, Google Docs for our documents, and Facebook and Twitter for our social lives. Android offers the ability to integrate all of this natively. Your Gmail account can be automatically synchronized with your phone. Photos taken with your phone can be automatically uploaded to Flickr. Your phone can even be linked to your Facebook account and can sync your phone contacts with your Facebook friends - complete with profile images, email addresses, and phone numbers. The iPhone can do this only through use of third party apps, and is nowhere near as seamless to use as the Android alternative.

10: Android Gives You More Options to Fit Your Budget 

If you've ever thought about buying an iPhone, you have probably noticed the price tag. The older iPhone 3G costs $99 with a two-year commitment and performs sluggishly with the latest OS updates when compared to the 3GS (which will run you a whopping $199 with two-year agreement). Because Android is an open source platform, it is very cost effective to implement which means savings for the end user. Every major cellular carrier (except for AT&T) has at least one Android phone available free with two-year agreement. Of course these are lower end Android devices, but they are still comparable in performance to the iPhone 3GS. The most expensive Android phones (which significantly outperform the iPhone 3GS) are  $199 with two-year contract.








Wednesday 27 April 2011

How to Start Multiple Thread in Android

here is the code of java where define two thread for android application main class


package com.practice.secondhand;

import java.util.Date;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;

public class SecondHand extends Activity {
// private Handler mHandler = new Handler();
protected static final String TAG = SecondHand.class.getName();
private ImageView img;
Handler mHandler;

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Thread myThread = null;
Runnable runnable = new CountDownRunner();
myThread = new Thread(runnable);
myThread.start();

}

private void doPlay(){
new Thread(new Runnable() {

@Override
public void run() {
// TODO Auto-generated method stub

Log.v("log_tag", "this is seocond thread");

}
}).start();
}
public void doRotate() {

runOnUiThread(new Runnable() {
public void run() {
try {

Date dt = new Date();
int hours = dt.getHours();
int minutes = dt.getMinutes();
int seconds = dt.getSeconds();
String curTime = hours + ":" + minutes + "::" + seconds;
Log.v("log_tag", "Log is here Time is now" + curTime);
img = (ImageView) findViewById(R.id.imgsecond);
RotateAnimation rotateAnimation = new RotateAnimation((seconds - 1) * 6, seconds * 6,
Animation.RELATIVE_TO_SELF, 0.5f,Animation.RELATIVE_TO_SELF, 0.5f);

rotateAnimation.setInterpolator(new LinearInterpolator());
rotateAnimation.setFillAfter(true);

img.startAnimation(rotateAnimation);
} catch (Exception e) {
Log.e("log_tag", "Error msg is " + e.toString());

}
}
});
}

class CountDownRunner implements Runnable {
// @Override
public void run() {
while (!Thread.currentThread().isInterrupted()) {
try {
// Log.v("log_tag", "Roate is going");
doRotate();
Thread.sleep(1000);
doPlay();
} catch (InterruptedException e)
{
// Thread.currentThread().interrupt();
} catch (Exception e) {
Log.e("log_tag", "Error is " + e.toString());
}
}
}
}

}


in this class doRotate(); function is for the updating ui thread in my class it is for the analog clock second hand for updating second hand .and doPlay() is thread for doing any other thing at every one second.

Wednesday 20 April 2011

How to make Custom Menu Bar –Tabs in Android Application and How to Hook the menu button to show/hide a custom tab bar

    I find this Example from the Website and share At the Blogs Which I will update time to time .By using this example one can we use it as tab Activity in android or it will be become more useful to Menu Bar.

The subject of this tutorial is how to create your own custom menu bar that will be shown and hidden when user clicked the menu button on his/her device.

There are many other uses for this example and it just isn’t limited to a menu or tab bar. For example, you can use this to show and hide a panel that contains whatever content you want to be shown. It could be used for contextual help or Media Player controls, etc.

Custom Menu Panel

The basis of this example is the layout. I have found that the RelativeLayout is superior for creating great layouts that perform well across devices. If you want to learn more about what a Relative Layout can do for you I highly recommend that you check out Working with Multiple Android Screens in the Motorola Android Technical Library. For the purpose of this tutorial… I haven’t followed everything that I should have as far as creating a good cross device application by defining my layouts using dip (Density Independent Pixels)… but this is just an example. Now let’s get to it.

The main layout for the application contains 2 Relative Layouts, a Text View, a Tab Host, aTabWidget and a View. In particular, I want to point out the layout_align ParentBottom attribute of the panel Relative Layout. This attribute is one of 4 separate attributes that allow you to place a Relative Layout on any side of the parent layout. I also want to bring your attentions to the visibility attribute which allows us to set the layout as hidden. Using “gone” makes the layout to be completely hidden, as if the view had not been added.

/res/layout/main.xml
 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@drawable/background"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView
        android:background="#000000"
        android:id="@+id/content"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:text="">
    </TextView>    
    <RelativeLayout
        android:layout_alignParentBottom="true"
        android:id="@+id/menuPopup"
        android:background="@drawable/tl_bg"
        android:layout_width="fill_parent"
        android:layout_height="90px"
        android:visibility="gone">
            <TabHost
                android:id="@android:id/tabhost" 
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">
            <LinearLayout 
                android:orientation="vertical"
                android:layout_width="fill_parent" 
                android:layout_height="fill_parent">
                <View 
                    android:layout_width="fill_parent" 
                    android:layout_height="0.5dip"
                    android:background="#000">
                </View>
                <TabWidget 
                    android:id="@android:id/tabs"
                    android:layout_width="fill_parent" 
                    android:layout_height="fill_parent"
                    android:layout_marginLeft="0dip" 
                    android:layout_marginRight="0dip">
                </TabWidget>
                <View 
                    android:layout_width="fill_parent" 
                    android:layout_height="2dip"
                    android:background="#696969">
                </View>
                <View 
                    android:layout_width="fill_parent" 
                    android:layout_height="2dip"
                    android:background="#000">
                </View>
                <FrameLayout 
                    android:id="@android:id/tabcontent"
                    android:layout_width="fill_parent" 
                    android:layout_height="fill_parent">
                </FrameLayout>
            </LinearLayout>
        </TabHost>
    </RelativeLayout>
</RelativeLayout>

The second layout is for each individual tab. I am not going to go into how to customize the tabs in this tutorial.

/res/layout/tabs_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tabsLayout" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:background="@drawable/tab_bg_selector"
    android:padding="5px" 
    android:gravity="center" 
    android:orientation="vertical">
    <ImageView 
        android:id="@+id/tabsIcon"
        android:layout_width="36px"
        android:layout_height="36px">
    </ImageView>
    <TextView 
        android:id="@+id/tabsText" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="5px"
        android:text=""
        android:textSize="12px"
        android:textColor="@drawable/tab_text_selector">
    </TextView>
</LinearLayout>

The first activity is called CustomMenuBar.java

package com.androidvogue.example.custommenubar;



import android.app.TabActivity;
import android.content.Context;

import android.content.Intent;

import android.os.Bundle;

import android.view.KeyEvent;

import android.view.LayoutInflater;

import android.view.View;

import android.widget.ImageView;

import android.widget.RelativeLayout;

import android.widget.TabHost;

import android.widget.TabHost.TabContentFactory;

import android.widget.TabHost.TabSpec;

import android.widget.TextView;



public class CustomMenuBar extends TabActivity {

               

                private TabHost mTabHost;

                private static RelativeLayout mMenuPanel;

                private TextView content;

private final static String WEBSITE = "http://www.android-vogue.blogspot.com";

               

                // This isn't necessary but it makes it nice to determine which tab I am on in         //the switch statement below

                private static class TabItem {

                                public final static int SEARCH = 0;

                                public final static int SHARE = 1;

                                public final static int WEBSITE = 2;

                                public final static int SETTINGS = 3;

                                public final static int QUIT = 4;

                }

               

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        setupViews();

    }

   

    private void setupViews() {

               

                content = (TextView) findViewById(R.id.content);

                content.setText(getString(R.string.search));

               

                mMenuPanel = ((RelativeLayout) findViewById(R.id.menuPopup));

                mMenuPanel.setVisibility(View.GONE);

                               

                mTabHost = (TabHost) findViewById(android.R.id.tabhost);

                                mTabHost.setup();

                               

                mTabHost.getTabWidget().setDividerDrawable(R.drawable.tab_divider);            

               

                addActivityTab(new TextView(this), "Search", R.drawable.search, new Intent(CustomMenuBar.this, Search.class));

                                addActivityTab(new TextView(this), "Share", R.drawable.heart, new Intent(CustomMenuBar.this, Share.class));

                                addMethodTab(new TextView(this), "Website", R.drawable.globe);

                                addActivityTab(new TextView(this), "Settings", R.drawable.tools, new Intent(CustomMenuBar.this, Settings.class));

                                addMethodTab(new TextView(this), "Quit", R.drawable.power);



                                mTabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {

                                                @Override

                                                public void onTabChanged(String arg0) {

                                                                if (mMenuPanel != null) {

                                                                                if (mMenuPanel.getVisibility() == View.VISIBLE) {                                                                   

                                                                                                toggleMenu();

                                                                                }

                                                                                switch (mTabHost.getCurrentTab()) {

                                                                                                case TabItem.SEARCH:

                                                                                                                content.setText(getString(R.string.search));

                                                                                                                break;

                                                                                                case TabItem.SHARE:

                                                                                                                content.setText(getString(R.string.share));

                                                                                                                break;

                                                                                                case TabItem.WEBSITE:

                                                                                                                content.setText(getString(R.string.website));

                                                                                                                final Intent visit = new Intent(Intent.ACTION_VIEW);

                                                                                                                visit.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                                                                                                                visit.setData(android.net.Uri.parse(WEBSITE));

                                                                                                               

                                                                                                                // Use a thread so that the menu is responsive when clicked

                                                                                                                new Thread(new Runnable() {

                                                                                                                                public void run() {

                                                                                                                                                startActivity(visit);

                                                                                                                                }

                                                                                                                }).start();                                                                               

                                                                                                                break;

                                                                                                case TabItem.SETTINGS:

                                                                                                                content.setText(getString(R.string.settings));

                                                                                                                break;

                                                                                                case TabItem.QUIT:

                                                                                                                content.setText(getString(R.string.quit));

                                                                                                                new Thread(new Runnable() {

                                                                                                                                public void run() {                                                                                                              

                                                                                                                                                CustomMenuBar.this.finish();

                                                                                                                                               

                                                                                                                                                // The following makes the Android Gods frown upon me

                                                                                                                                                android.os.Process.killProcess(android.os.Process.myPid());

                                                                                                                                                System.exit(0);

                                                                                                                                }

                                                                                                                }).start();

                                                                                                                break;

                                                                                                default:

                                                                                                                break;

                                                                                }

                                                                               

// Handle click on currently selected tab - hide menu bar

// IMPORTANT: This listener has to appear AFTER the tabs are added

// Unfortunately, This doesn't work when the current tab contains an activity (except for tab 0)

// If you only have method tabs then it works perfect



mTabHost.getTabWidget().getChildAt(mTabHost.getCurrentTab()).setOnClickListener(new View.OnClickListener() {

                                                                                               

                                                @Override

                                                public void onClick(View v)

{



                                                toggleMenu();

                                                                }

                                                                                });

                                                                               

                                                                                //if you want to reset the current tab

                                                                                // mTabHost.setCurrentTab(0);

                                                                }

                                                }

                                });

    }

   

    // Use this method to add an activity or intent to the tab bar

    private void addActivityTab(final View view, final String tag, int iconResource, Intent intent) {

                                View tabview = createTabView(mTabHost.getContext(), tag, iconResource);

                                 

                                TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabview)

                                                                .setContent(intent);

                                mTabHost.addTab(setContent);



                }

   

    // Use this method if you only want the tab to execute a method

    private void addMethodTab(final View view, final String tag, int iconResource) {

                                View tabview = createTabView(mTabHost.getContext(), tag, iconResource);



                                TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabview)

                                                                .setContent(new TabContentFactory() {

                                                                                public View createTabContent(String tag) {

                                                                                                return view;

                                                                                }

                                                                });

                                mTabHost.addTab(setContent);



                }

   

    private static View createTabView(final Context context, final String text,

                                                int iconResource) {

                                View view = LayoutInflater.from(context)

                                                                .inflate(R.layout.tabs_layout, null);

                                TextView tv = (TextView) view.findViewById(R.id.tabsText);

                                tv.setText(text);



                                ImageView icon = (ImageView) view.findViewById(R.id.tabsIcon);

                                icon.setImageResource(iconResource);



                                return view;

                }

   

    @Override

                public boolean onKeyDown(int keyCode, KeyEvent event) {

                                if (keyCode == KeyEvent.KEYCODE_MENU) {

                                                toggleMenu();

                                                return true;

                                } else {

                                                return super.onKeyDown(keyCode, event);

                                }

                               

    }

   

    public static void toggleMenu() {

                                if (mMenuPanel.getVisibility() == View.GONE) {

                                                mMenuPanel.setVisibility(View.VISIBLE);

                                } else {

                                                mMenuPanel.setVisibility(View.GONE);

                                }                             

                }
}
Here is one of the example activities that are set as content for the activity tabs. I will only publish this one because they are identical.

Search.java



package com.androidvogue.example.custommenubar;



import android.app.Activity;

import android.os.Bundle;

import android.view.KeyEvent;

import android.widget.TextView;



public class Search extends Activity {



                @Override

                public void onCreate(Bundle savedInstanceState) {

                                super.onCreate(savedInstanceState);

        setupViews();                               

                }

               

                private void setupViews() {

                                /* Search Tab Content */

                                TextView textView = new TextView(this);

                                textView.setText(getString(R.string.search));

                                setContentView(textView);

                }

               

                @Override

                public boolean onKeyDown(int keyCode, KeyEvent event) {

                                if (keyCode == KeyEvent.KEYCODE_MENU) {

                                                CustomMenuBar.toggleMenu();

                                                return true;

                                } else {

                                                return super.onKeyDown(keyCode, event);

                                }

                               

    }

}



The code in CustomMenuBar.java is commented and you should be able to follow what it does… I am going to concentrate on the primary subject of this tutorial which is hooking the menu button and displaying and hiding the menu panel. First, it is very easy to hook the menu button. This is accomplished by overriding the onKeyDown method of the activity and catching the KeyEvent for the menu button. If you look at the KeyEvent page in the SDK documentation you can see that there are many KeyEvent constants that allow you to hook almost any key.

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_MENU) {
        toggleMenu(); // show or hide the menu as required
        return true;
    } else {
        return super.onKeyDown(keyCode, event);
    }   
}

The next important part is the toggleMenu()_ method which just sets the visibility of the panel. Notice that the modifier of the method is static. This allows us to call this method from another activity. I will go into more detail below.

public static void toggleMenu() {
    if (mMenuPanel.getVisibility() == View.GONE) 
{
mMenuPanel.setVisibility(View.VISIBLE);
    } else {
            mMenuPanel.setVisibility(View.GONE);
    }       
}

Now look at Search.java above. You will notice that it also has the Overriden onKeyDown method. This is because only the currently active Activity can catch KeyEvents. So we have to Override that method in each of the activities that we are using. The difference in these activities is that they don’t have access to the panel… only CustomMenuBar has access to it… so the workaround to be able to toggle the menu is to call the method directly in CustomMenuBar. This is the static call I mentioned above. Notice that in Search.java I am calling toggleMenu() like CustomMenuBar.toggleMenu();.

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_MENU) {
        CustomMenuBar.toggleMenu();
        return true;
    } else {
        return super.onKeyDown(keyCode, event);
    }       
}