Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build a Self-Destructing Message Android App Adding Users Using Parse.com Adding a Progress Indicator

Wei-Ting Chen
Wei-Ting Chen
7,632 Points

After adding "requestWindowFeature", I can't open Ribbit

Hi everyone, in the "adding a Progress Indicator" course, after I correctly put" requestWindowFeature" and " setProgressBarIndeterminateVisibility" in the code,then I run Ribbit on both my phone and emulator ,but all of them show "Unfortunately,Ribbit has stopped."

Any suggestion?

Thanks

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
        setContentView(R.layout.activity_login);

        mSignUpTextView=(TextView)findViewById(R.id.signupText);
        mSignUpTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(LoginActivity.this,SignupActivity.class);
                startActivity(intent);
            }
        });
        mUsername= (TextView) findViewById(R.id.usernameField);
        mPassword= (TextView) findViewById(R.id.passwordField);
        mLoginButton= (Button) findViewById(R.id.loginButton);

        mLoginButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String username=mUsername.getText().toString();
                String password=mPassword.getText().toString();

                username=username.trim();
                password=password.trim();

                if(username.isEmpty() || password.isEmpty() ) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this);
                    builder.setMessage(R.string.login_error_message)
                            .setTitle(R.string.login_error_title)
                            .setPositiveButton(android.R.string.ok,null);
                    AlertDialog dialog=builder.create();
                    dialog.show();
                }
                else{
                    setProgressBarIndeterminateVisibility(true);

                    ParseUser.logInInBackground(username, password,new LogInCallback() {
                        @Override
                        public void done(ParseUser user, ParseException e) {
                            setProgressBarIndeterminateVisibility(false);

                            if(e==null){
                                //success
                                Intent intent=new Intent(LoginActivity.this,MainActivity.class);
                                //clear history in case user touch "go back" button
                                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
                                startActivity(intent);
                            }else{
                                AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this);
                                builder.setMessage(e.getMessage())
                                        .setTitle(R.string.login_error_title)
                                        .setPositiveButton(android.R.string.ok, null);
                                AlertDialog dialog=builder.create();
                                dialog.show();
                            }
                        }
                    });
                }
            }
        });
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_login, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}
Wei-Ting Chen
Wei-Ting Chen
7,632 Points

Well after I google a while, I find it works by change the "requestWindowFeature" before "super.onCreate" (http://stackoverflow.com/questions/16939814/android-util-androidruntimeexception-requestfeature-must-be-called-before-add)

But there comes another question: WHY does the progress bar still not show up??

progressbar is actually a spinning circle in your menu bar, it is not an actual horizontal progress bar like you see on some of the other apps. That bar has a different name.

Christiaan Hendriksen
Christiaan Hendriksen
5,982 Points

Moving it above super.onCreate fixed the error for me too, but I'm not getting the spinner to show up either.

Chris Quinlan
Chris Quinlan
4,742 Points

I changed my code to

supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

and left it right after onCreate and before setContenctView.

This fixed the crashing application but I still do not see the spinner in the login or signup.

6 Answers

Timo M
Timo M
3,823 Points

The Progress Spinner in the Action Bar is deprecated, see Issue 78049.

You can still implement it without crashing the app by calling the requestWindowFeature() before the super.onCreate(), but setProgressBarIndeterminateVisibility() won't do anything.

If you really want to, you can find a solution to provide a Spinner in the Action Bar on Stackoverflow. This doesn't use the Action Bar as you know it itself, instead it uses a Toolbar, which will be set as Action Bar. Since Google surely had a reason to make this deprecated, I wouldn't recommend it.

To follow the Android Design Guidelines, simply use a ProgressBar in your Layout. Show and hide it, as it was made in the Blog Reader Tutorial (if I remember correctly).

From the Dialogs API Guides, as at 18th January 2015:

Avoid ProgressDialog: Android includes another dialog class called ProgressDialog that shows a dialog with a progress bar. However, if you need to indicate loading or indeterminate progress, you should instead follow the design guidelines for Progress & Activity and use a ProgressBar in your layout.

Michael Brennan
Michael Brennan
6,128 Points

This is the answer, should be at the top and this video should probably be removed or refactored, Thanks Timo

Thanks

Noah Schill
Noah Schill
10,020 Points

A better solution, instead of working with this antiquated method, would be to first create a progressBar in the layout editor. Then declare it as a member variable in LoginActivity:

mProgressBar = (ProgressBar) findViewById(R.id.progressBar);

Then you have to set it to invisible (as it is visible by default). Make sure you add it before the rest of your member variables, or it will just spin before the user even does anything:

mProgressBar.setVisibility(View.INVISIBLE);

You can then place this code wherever you need to just by toggling this parameter to View.VISIBLE.

I know this is somewhat and older post, but I hope it helps someone!

I ended up doing the same thing. I just added the progress bar (circle) below the buttons on the two different screens.

jenyufu
jenyufu
3,311 Points

should we set it to private:

    private ProgressBar mProgressBar;

or protected?

protected ProgressBar mProgressBar;
Wei-Ting Chen
Wei-Ting Chen
7,632 Points

@Christiaan Hendriksen me too : (

Tom Schinler
Tom Schinler
21,052 Points

I was having the same issue, I am using Android Studio, is that what you are all using as well? I Moved the requestWindowFeature() above the super.onCreate and app stopped crashing. @BenJakuben any ideas on why the spinner will not work?

Rustam Eynaliyev
Rustam Eynaliyev
1,993 Points

I have the same problem. Moving the requestWindowFeature above the super.onCreate helped me solve the crashing issue, but the spinner still isn't showing.