Starting activity from onPostExecute(String result) doesn't set ui flags

Rob85

My overall goal here is to hide the navigation bars when I start an activity in my Android app.

I have two activities, the first one is a login screen and has an async task running and depending on the out come of the result I start my new activity

OnPostExecute in first activity

 .....

 @Override
    protected void onPostExecute(String result)
    {

        try
        {
            if (result.equals("true"))
            {
                Intent intent = new Intent(mContext, MainRota.class);
                startActivity(intent);
                finish();

            }
            else
            {
                CharSequence text = "One or more fields are incorrect!";
                int duration = Toast.LENGTH_SHORT;
                Toast toast = Toast.makeText(mContext, text, duration);
                toast.show();
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

The second activity immediately sets the ui flags to hide the nav bars

OnCreate of second activity

.....

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.my_layout);

    View decorView = getWindow().getDecorView();
 // Hide both the navigation bar and the status bar.
 // SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as
 // a general rule, you should design your app to hide the status bar whenever you
// hide the navigation bar.
    int uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                             | View.SYSTEM_UI_FLAG_FULLSCREEN
                             | View.SYSTEM_UI_FLAG_IMMERSIVE
                             | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                             | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;

    decorView.setSystemUiVisibility(uiOptions);
}

when the second activity is started it is almost as if the flags are ignored and the bars are not hidden.

If i start the second activity straight from the onCreate of the first activity it works fine, but obviously i am by passing my login doing this.

Does anyone know why this happens and how to fix as I was under the impression onPostExecute runs on the main thread so there shouldn't be a problem starting an activity here.

Update!!

I have found what is causing the issue but i am still not sure why.

From the login activity i had added a listener so that when you typed the password in and pressed "done" it logged straight in rather than having to hit the login button. If i remove this listener and go back to using the login button it works fine. here is my listener code.

((EditText)findViewById(R.id.password)).setOnEditorActionListener(
      new EditText.OnEditorActionListener() 
      {
          @Override
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
          {
              if (actionId == EditorInfo.IME_ACTION_SEARCH ||
                          actionId == EditorInfo.IME_ACTION_DONE ||
                          event.getAction() == KeyEvent.ACTION_DOWN &&
                                  event.getKeyCode() == KeyEvent.KEYCODE_ENTER)
              {
                  new GetJSONResult().execute("");
                  return true;
              }
              return false;
          }
      });

and here is my login button

    LoginButton = (Button) findViewById(R.id.loginButton2);
    LoginButton.setOnClickListener(new View.OnClickListener()
    {
        @Override
        public void onClick(View arg0)
        {
            new GetJSONResult().execute("");
        }
    });

So the question now is, why would calling the asyncTask from the listener on the EditText cause the systemUI flags to be ignored on the new activity I start from the OnPostExecute

SweetWisher ツ

Simply return false from OnEditorActionListener method.
Just a little bit change in your code:

((EditText)findViewById(R.id.password)).setOnEditorActionListener(
      new EditText.OnEditorActionListener() 
      {
          @Override
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
          {
              if (actionId == EditorInfo.IME_ACTION_SEARCH ||
                          actionId == EditorInfo.IME_ACTION_DONE ||
                          event.getAction() == KeyEvent.ACTION_DOWN &&
                                  event.getKeyCode() == KeyEvent.KEYCODE_ENTER)
              {
                  new GetJSONResult().execute("");
              }
              return false;
          }
      });

I have checked it and it's working fine for me.

Hope this will help you ツ

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Starting activity from Fragment doesn't work Xamarin

From Dev

starting an activity for result from another activity that should return a result

From Dev

Starting an activity from a service and wait for the result

From Dev

Starting an activity from a service and wait for the result

From Dev

Starting an Activity for result in Fragment

From Dev

Starting activity doesn't call onDestory of current activity

From Dev

Android notification starting new instance of activity no matter what the launchMode and/or flags are set to

From Dev

Multiple Intent flags for starting a new Activity in Android

From Dev

open another activity when got a result "success" from php webservice But doesn't work, android

From Dev

After changing Android starting activity, app doesn't launch

From Dev

Starting Activity From Within Activity

From Dev

Changing Main Activity in Manifest result to shortcuts doesn't work anymore

From Dev

Android set view flags for AppCompat activity with XML

From Dev

Get result from facebook activity without onActivityResult set for session

From Dev

Fragment of Fragment starting Activity for result Issue

From Dev

Compiler doesn't recognize flags

From Dev

Starting activity from a separate thread?

From Dev

Android Service Not Starting From Activity

From Dev

Starting activity from fragment not working

From Dev

Starting new activity from onOptionsItemSelected

From Dev

Starting another Activity from an Alertdialog

From Dev

Error starting activity from BroadcastReceiver

From Dev

can't get the same result after changing from activity to fragment

From Dev

Set ImageView in XML before starting activity

From Dev

Removing activity from activity stack and starting new instance of the requested activity

From Dev

Activity doesn't start

From Dev

Can't resolve activity for result

From Dev

Can't resolve activity for result

From Dev

Activity extended from CameraBridgeViewBase (OpenCV) doesn't make camera connection

Related Related

  1. 1

    Starting activity from Fragment doesn't work Xamarin

  2. 2

    starting an activity for result from another activity that should return a result

  3. 3

    Starting an activity from a service and wait for the result

  4. 4

    Starting an activity from a service and wait for the result

  5. 5

    Starting an Activity for result in Fragment

  6. 6

    Starting activity doesn't call onDestory of current activity

  7. 7

    Android notification starting new instance of activity no matter what the launchMode and/or flags are set to

  8. 8

    Multiple Intent flags for starting a new Activity in Android

  9. 9

    open another activity when got a result "success" from php webservice But doesn't work, android

  10. 10

    After changing Android starting activity, app doesn't launch

  11. 11

    Starting Activity From Within Activity

  12. 12

    Changing Main Activity in Manifest result to shortcuts doesn't work anymore

  13. 13

    Android set view flags for AppCompat activity with XML

  14. 14

    Get result from facebook activity without onActivityResult set for session

  15. 15

    Fragment of Fragment starting Activity for result Issue

  16. 16

    Compiler doesn't recognize flags

  17. 17

    Starting activity from a separate thread?

  18. 18

    Android Service Not Starting From Activity

  19. 19

    Starting activity from fragment not working

  20. 20

    Starting new activity from onOptionsItemSelected

  21. 21

    Starting another Activity from an Alertdialog

  22. 22

    Error starting activity from BroadcastReceiver

  23. 23

    can't get the same result after changing from activity to fragment

  24. 24

    Set ImageView in XML before starting activity

  25. 25

    Removing activity from activity stack and starting new instance of the requested activity

  26. 26

    Activity doesn't start

  27. 27

    Can't resolve activity for result

  28. 28

    Can't resolve activity for result

  29. 29

    Activity extended from CameraBridgeViewBase (OpenCV) doesn't make camera connection

HotTag

Archive