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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:40:21+00:00 2026-06-16T05:40:21+00:00

I have an login screen for my app. (spinner, edittext, button) and i want

  • 0

I have an login screen for my app. (spinner, edittext, button) and i want to store the spinner selected item and the inputted text to sharedpreferences. to use everywhere in the app.

code

Button lgnbutton;
EditText lgnfield;
Spinner lgnspinner;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);

lgnbutton = (Button) findViewById(R.id.loginbutton);
lgnfield = (EditText) findViewById(R.id.loginfield);
lgnspinner = (Spinner) findViewById(R.id.loginspinner);





lgnbutton.setOnClickListener(new View.OnClickListener() {

    public void onClick(View v) {
        // TODO Auto-generated method stub

        String ID = lgnfield.getText().toString();
        String Type = lgnspinner.getSelectedItem().toString();


        Intent myIntent = new Intent(LoginActivity.this, MainActivity.class);
        LoginActivity.this.startActivity(myIntent);
    }
});
}    
}

Also it would be nice to skip the loginactivity and proceed to the mainactivity.

  • 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-16T05:40:22+00:00Added an answer on June 16, 2026 at 5:40 am

    you can store login details and spinner selected item as in SharedPreferences

    lgnbutton.setOnClickListener(new View.OnClickListener() {
    
        public void onClick(View v) {
            // TODO Auto-generated method stub
    
             ID = lgnfield.getText().toString();
             Type = lgnspinner.getSelectedItem().toString();
    
            SharedPreferences.Editor prefsEditor = loginpreferences.edit();
            prefsEditor.putString("ID", ID);
            prefsEditor.putString("Type", Type);
            prefsEditor.commit();
    
            Intent myIntent = new Intent(LoginActivity.this, MainActivity.class);
            LoginActivity.this.startActivity(myIntent);
        }
    });
    

    and in onCreate of LoginActivity check if login details exist in SharedPreferences if yes then move to MainActivity as :

    SharedPreferences loginpreferences;
    String ID="",Type="";
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        loginpreferences = this.getSharedPreferences("loginPrefs", 
                                                MODE_WORLD_READABLE);
    
        ID = loginpreferences.getString("ID", "");
        Type = loginpreferences.getString("Type", "");
    
         if(!ID.equalsIgnoreCase("") && !Type.equalsIgnoreCase(""))
          {
            //move to MainActivity
          }else
         {
           //stay in LoginActivity
         }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a login screen view and 5 tabs in the app.I want when
My iphone app have login screen, and logout button in the app, requierment was
My app has a main screen where i have button to go to login
I have an app with a login screen with a button that invites users
I have following flow of app : First screen is Login screen and if
I have an app that starts out in the login screen and when you
My app needs to have multiple screen e.g. one login page then another page
I have a login screen and there is some registration button and login button.
I am writing an app and I want to show the login screen just
I have a login screen on my app which accepts a CPF as login

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.