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

  • Home
  • SEARCH
  • 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 7512341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:50:10+00:00 2026-05-29T23:50:10+00:00

I am using authentication to enter into a page, after authenticated only the user

  • 0

I am using authentication to enter into a page, after authenticated only the user enters into the page. i wrote a code for onbackpressed(), but it is not working. Here DatabaseDemo and Login are the two classes. when i press the back button the login class with username and password is displaying.

DatabaseDemo.java

public class DatabaseDemo extends TabActivity {
    DatabaseHelper dbHelper;
    GridView grid;
    TextView txtTest;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        SetupTabs();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        menu.add(1, 1, 1, "Add Employee");
        return true;
    }
    public boolean onOptionsItemSelected(MenuItem item)
    {
        switch (item.getItemId())
        {
        //Add employee
        case 1:
            Intent addIntent=new Intent(this,AddEmployee.class);
            startActivity(addIntent);
            break;
        }
        super.onOptionsItemSelected(item);
        return false;
    }
    void SetupTabs()
    {
        TabHost host=getTabHost();
        TabHost.TabSpec spec=host.newTabSpec("tag1");
        Intent in1=new Intent(this, AddEmployee.class);
        spec.setIndicator("Add Employee");
        spec.setContent(in1);

        TabHost.TabSpec spec2=host.newTabSpec("tag2");
        Intent in2=new Intent(this, GridList.class);

        spec2.setIndicator("Employees");
        spec2.setContent(in2);

        host.addTab(spec);
        host.addTab(spec2);
    }
    @Override
    public void onBackPressed() 
    {
        Intent i = new Intent(DatabaseDemo.this, Login.class);
        startActivity(i);
    }
}

I am having some more classes, it is working fine for the other intents.

Login.java

public class Login extends Activity implements OnClickListener{
    Button btn;
    EditText et1, et2;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);

        btn = (Button)findViewById(R.id.btnlogin);
        btn.setOnClickListener(this);
        et1 = (EditText)findViewById(R.id.Leditename);
        et2 = (EditText)findViewById(R.id.Leditpw);

    }
    @Override
    public void onBackPressed() 
    {
        super.onBackPressed();
        finish();
    }
    @Override
    public void onClick(View v) {
        String ename = et1.getText().toString().trim();
        System.out.println("ename is..." +ename);
        String epw = et2.getText().toString().trim();
        System.out.println("Password is..." +epw);

        if(ename.equals("srikanth") && epw.equals("12345")){
            Toast.makeText(getApplicationContext(), "valid login..!", Toast.LENGTH_LONG).show();
            Intent in = new Intent(getApplicationContext(), DatabaseDemo.class);
            startActivity(in);      
        }
        else
        {
            Toast.makeText(getApplicationContext(), "Invalid authentication..!", Toast.LENGTH_LONG).show();
            Intent intent = new Intent(getApplicationContext(), Login.class);
            startActivity(intent);
        }
    }

Logcat is showing no error.

02-14 17:45:33.595: I/ActivityManager(59): Starting activity: Intent { cmp=com.android.databaseex/.DatabaseDemo }
02-14 17:45:34.835: I/ActivityManager(59): Displayed activity com.android.databaseex/.DatabaseDemo: 1141 ms (total 1141 ms)
02-14 17:45:50.145: I/System.out(613): ename is...srikanth
02-14 17:45:50.145: I/System.out(613): Password is...12345
02-14 17:45:50.175: I/ActivityManager(59): Starting activity: Intent { cmp=com.android.databaseex/.DatabaseDemo }
02-14 17:45:51.055: I/ActivityManager(59): Displayed activity com.android.databaseex/.DatabaseDemo: 819 ms (total 819 ms)
  • 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-05-29T23:50:12+00:00Added an answer on May 29, 2026 at 11:50 pm

    you need to skip super.onBackPressed(); line:

    @Override
        public void onBackPressed() 
        {
            Intent i = new Intent(DatabaseDemo.this, Login.class);
            startActivity(i);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying out this basic authentication using jQuery. But nothing happens when I enter
I'm using forms authentication for an app that allows users to register but not
Using Forms Authentication in ASP.NET MVC when trying to log back into a site,
I am using forms authentication. My users are redirected to a page (written in
i am using form authentication for my website which is written in ASP.Net, but
My websrervice works using authentication, but the problem is that it's static, it's written
How can I access the basic information of a user without using authentication mechanism
Following this tutorial i'm developing a web application using symfony authentication/authorization architecture. After designing
i am using spring security 3 when i enter wrong data user is redirected
I am writing a functional test for a page that requires user authentication. 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.