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"
android:finishOnTaskLaunch="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...

 main.class

  public class main extends Activity {
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            //set up main content view
            setContentView(R.layout.main);
            //this button will show the dialog
            Button button1main = (Button) findViewById(R.id.Button01main);
     
            button1main.setOnClickListener(new OnClickListener() {
            @Override
                public void onClick(View v) {
                    //set up dialog
                    Dialog dialog = new Dialog(main.this);
                    dialog.setContentView(R.layout.maindialog);
                    dialog.setTitle("This is my custom dialog box");
                    dialog.setCancelable(true);
                    //there are a lot of settings, for dialog, check them all out!
     
                    //set up text
                    TextView text = (TextView) dialog.findViewById(R.id.TextView01);
                    text.setText(R.string.lots_of_text);
     
                    //set up image view
                    ImageView img = (ImageView) dialog.findViewById(R.id.ImageView01);
                    img.setImageResource(R.drawable.nista_logo);
     
                    //set up button
                    Button button = (Button) dialog.findViewById(R.id.Button01);
                    button.setOnClickListener(new OnClickListener() {
                    @Override
                        public void onClick(View v) {
                            finish();
                        }
                    });
                    //now that the dialog is set up, it's time to show it    
                    dialog.show();
                }
            });
        }
     }

Check out this may be help you

Related Posts Plugin for WordPress, Blogger...