Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8858595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:51:57+00:00 2026-06-14T14:51:57+00:00

I created a login app represented by 2 EditText (username,password) and a button. When

  • 0

I created a login app represented by 2 EditText (username,password) and a button.
When I click login it checks of course the information and if it’s wrong it prints a dialog with a try again button.
When I go back to the login activity the old username and password text are still there and I want to reset it.
I tried to do that on the onPause() method since when the error dialog pops up the onPause() method is generated but I failed.

Any Idea?
Thanks.

edit: after your advices I decided to re-arrannge my code and declare the EditText as they should be.
The result is still the same =\

public class MainActivity extends Activity 
{
    public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";
    private EditText username,password;

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

    this.username = (EditText)findViewById(R.id.username);
    this.password = (EditText)findViewById(R.id.password);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) 
{
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}
@Override
public void onPause()
{
    this.username.setText("");
    this.password.setText("");

    super.onPause();
}
public void showMsg(View view)
{
    String user = this.username.getText().toString();
    String pass = this.password.getText().toString();

    if(user.equals("a") && pass.equals("a"))
    {
        Intent i1 = new Intent(this,DisplayMessageActivity.class);
        i1.putExtra(EXTRA_MESSAGE, user);
        startActivity(i1);
    }
    else
    {   
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Error!");
        builder.setMessage(R.string.failure);
        builder.setPositiveButton("Try again", null);
        builder.show();
    }
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T14:51:58+00:00Added an answer on June 14, 2026 at 2:51 pm

    I tried to do that on the onPause() method since when the error dialog pops up the onPause() method is generated but I failed.

    I have no idea what that means, but you should be able to do something like:

    @Override
    protected void onPause() {
        editText.setText("");
        super.onPause();
    }
    

    If this doesn’t help guide you, you need to post what you have tried and the LogCat errors. Otherwise we won’t be able to help…


    Addition
    You don’t actually leave the Activity when the username and password combination is wrong, so onPause() is never called. Try this:

    public void showMsg(View view)
    {
        String user = this.username.getText().toString();
        String pass = this.password.getText().toString();
        this.username.setText("");
        this.password.setText("");
    

    Or if you only want to clear the username and password in the else-block (where you create the AlertDialog).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created login demo.I am parsing username and password using JSON parser which
I'm using VS2008 and I created an app with a login screen. That screen
I want to create login and password fields same as in facebook app for
I created a small popup window in android app for login form shown in
I have successfully created an app to login user and post the tweet using
I created a login activity for my Android app. After the user enters the
I have created a login page for an App I am creating. I am
I've created on a local machine (XAMPP) app with login and it works great.
I have created a django app. I have implemented a facebook login along with
I created a login process for an iPhone app I am developing, and the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.