Android Show Soft Keyboard When First Activity Starts?

I need to display the virtual keyboard when the application starts, but so far I've failed.

I use this code in method "OnCreate"to display the virtual keyboard

    InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(txtBuscar.getId(), InputMethodManager.SHOW_FORCED);

this code works fine on any screen at any time, but does not work when the "first" activity begins. Why?

I tried it when I start another activity and it works, but does not work when I start the "first"activity.

I tried to put this code in the events "OnCreate"and many more .... but it seems not work.

is there anyway to "force" to display the keyboard when I start the application?

Thanks in advance.


I Found the solution:

txtPassword.postDelayed(new Runnable() {
            public void run() {
                InputMethodManager keyboard = (InputMethodManager)
                keyboard.showSoftInput(txtPassword, 0); 

Thanks !!!

onCreate will not be called if the activity is first brought from background. Have you tried put that code in onResume?

onCreate is called only when activity is first start or the activity is killed and user navigate to the activity again. So if the activity is still alive but in background, it will not call onCreate.

On the other hand, onResume will be called every time the activity comes to foreground (visible on screen) from background.

Here is link to activity life cycle if you are interested

Hope it helps.

I faced with the same issue, this method below helped me

public static void showKeyboard(Context context) {
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imm != null) {
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);

Need Your Help

Interactive pixel information of an image in Python?

python image image-processing matplotlib scikit-image

Short version: is there a Python method for displaying an image which shows, in real time, the pixel indices and intensities? So that as I move the cursor over the image, I have a continually upda...

How to undo another user’s checkout in TFS?

tfs tfs2010 tfs2012 tfs2008 tfs2013

As the resident TFS admin, on occasion I am asked to undo a checkout (usually a lock) that a user has on a certain file checked into source control.