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 8885559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:20:18+00:00 2026-06-14T21:20:18+00:00

simple maybe stupid question. I have a login activity which launches another activity, and

  • 0

simple maybe stupid question. I have a login activity which launches another activity, and here’s the code:

public class LoginActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.login);
    ActionBar actionBar = getActionBar();
    actionBar.hide();

    Button btnLogin = (Button) findViewById(R.id.btnLogin);
    final TextView tvUsername = (TextView) findViewById(R.id.tvUsername);
    final TextView tvPassword = (TextView) findViewById(R.id.tvPassword);

    btnLogin.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (tvUsername.getText().toString().length()<1) {
                Toast msg = Toast.makeText(LoginActivity.this, "Enter a Username", Toast.LENGTH_LONG);
                msg.setGravity(Gravity.TOP|Gravity.LEFT, 0, 70);
                msg.show();
                tvUsername.requestFocus();
            } else if (tvPassword.getText().toString().length()<1) {
                Toast msg = Toast.makeText(LoginActivity.this, "Enter a Password", Toast.LENGTH_LONG);
                msg.setGravity(Gravity.TOP|Gravity.LEFT, 0, 200);
                msg.show();
                tvPassword.requestFocus();
            } else {
                startActivity(new Intent(LoginActivity.this,CrewScheduleActivity.class));
                finish();
            }
        }
    });
    }
}

My question is about the textviews. Eclipse basically said i had to make them final in order to use them in the onClick event of the button. NP so i did that and it worked.

The question is What is the difference between putting these above the @Override as private vs inside the OnCreate as final?

  • 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-14T21:20:19+00:00Added an answer on June 14, 2026 at 9:20 pm

    This has to do with closure in Java. Basically, when you use an anonymous class, the values (not objects themselves) used within it are copied to that class for usage. Therefore, it does not make sense to return or modify those variables within the class, hence they must be final.

    However, if the variable is instead part of the class containing the anonymous class, that’s different. Basically, your inner class has a reference to the LoginActivity object (as LoginActivity.this), and can use and modify its members and methods.

    When you put them “above the @Override”, you are making them member variables of the LoginActivity class. Therefore, they can be accessed by the anonymous class.

    Succinctly, the difference is that: final variables are local to the method, and copied to the anonymous class; member variables are local to the containing class and are modified by the anonymous class.

    If you want to reuse the data from the anonymous class later, use a member variable. If you only need it within onCreate() and the anonymous class, then a final variable will suffice.

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

Sidebar

Related Questions

I have a basic, simple and maybe stupid question, but how do I implement
I was wondering which is the way to make this simple (and maybe stupid)
Ok so this maybe a simple/silly question but I don't know so here goes:
Maybe a very simple question. How can I put in this code <Query> <Where>
This may be a weird or stupid question, but I have the following code
I'd like to ask you a simple question(maybe stupid one). Would you use Netbeans
I have a simple (may be stupid) question. I want to calculate Kullback–Leibler divergence
The question maybe too simple and stupid, however, I didn't get any useful information
my question seems simple and stupid but first read this, suppose you have a
I had a (maybe simple) question about the CAS protocol . From what I

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.