Thursday, September 29, 2011

Kill all activities when HOME key is pressed android

Kill all activities when HOME key is pressed android
Set android:clearTaskOnlaunch="true" on the activity launched from the home screen.
You might also check some of the other attributes you can specify on activity, to tweak it's behavior a bit more.
On main activity add:
    android:launchMode="singleTask" android:clearTaskOnLaunch="true"

How to remove focus and hide the on screen Keyboard?

How to remove focus and hide the on screen Keyboard.
EditTest on focus changed key board will hide. 
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editTextField.getWindowToken(), 0);
or onclick button key board hide... 
 btnSend.setOnClickListener(new OnClickListener() 
            public void onClick(View v) 
             //***Key Board Hide****//
             InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
             imm.hideSoftInputFromWindow(mOutEditText.getWindowToken(), 0);

Friday, September 23, 2011

Get Current Activity and Package Name in android

Get Current Activity  and Package Name in android.

    ActivityManager am = (ActivityManager) this .getSystemService(ACTIVITY_SERVICE);
   List<RunningTaskInfo> taskInfo = am.getRunningTasks(1);
    ComponentName componentInfo = taskInfo.get(0).topActivity;
    Log.d(WebServiceHelper.TAG, "CURRENT Activity ::" + taskInfo.get(0).topActivity.getClassName()+"   Package Name :  "+componentInfo.getPackageName());

Monday, September 19, 2011

Android: Refresh Activity from Notification

Android: Refresh Activity from Notification;

When creating the pending intent, one should pass PendingIntent.FLAG_UPDATE_CURRENT as such: PendingIntent contentIntent = PendingIntent.getActivity( context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT );

Wednesday, September 14, 2011

ERROR: the user data image is used by another emulator. aborting

ERROR: the user data image is used by another emulator. aborting

Go to .android folder from Users folder. Once you are in .android go to avd folder. Select the emulator, which you are using. Inside that folder you will see two folders:
cache.img.lock and userdata-qemu.img.lock. Delete both these folders and then just restart the emulator.

Thursday, September 1, 2011

Two layouts to be loaded for single activity

Two layouts to be loaded for single activity with custom dialog

How to display a custom dialog in your Android application
Yesterday Jozsi showed you, how to make an alert dialog, today I'm going to show you, how to make a custom dialog/popup window.
Sometimes, it's better to make your own dialog, because this way, you can display whatewer you want., the way you want it.
First, make your own layout, with the needed elements. Here, I'm going to use two buttons, a textview inside a scrollview, and an imageview...


  public class main extends Activity {
        public void onCreate(Bundle savedInstanceState) {
            //set up main content view
            //this button will show the dialog
            Button button1main = (Button) findViewById(;
            button1main.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    //set up dialog
                    Dialog dialog = new Dialog(main.this);
                    dialog.setTitle("This is my custom dialog box");
                    //there are a lot of settings, for dialog, check them all out!
                    //set up text
                    TextView text = (TextView) dialog.findViewById(;
                    //set up image view
                    ImageView img = (ImageView) dialog.findViewById(;
                    //set up button
                    Button button = (Button) dialog.findViewById(;
                    button.setOnClickListener(new OnClickListener() {
                        public void onClick(View v) {
                    //now that the dialog is set up, it's time to show it    

Check out this may be help you

Related Posts Plugin for WordPress, Blogger...