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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:21:51+00:00 2026-06-05T05:21:51+00:00

So I know it has to do with my startActivity( myIntent ) line of

  • 0

So I know it has to do with my “startActivity( myIntent )” line of code. Here is my first Activity file

public class Commander2 extends Activity {
    /** Called when the activity is first created. */

    private static final String TAG = "AccessCodeEntry";
    private static final String LEVEL_ONE_ACCESS_CODE = "derp";

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

protected void onDestroy() {
    super.onDestroy();
}

public void accessCodeEntered( View v ) {
    EditText loginPassword = (EditText) findViewById( R.id.editText1 );
    if( loginPassword.toString().equals( LEVEL_ONE_ACCESS_CODE ) ) {
        Intent myIntent = new Intent( Commander2.this, LevelOne.class );
        startActivity( myIntent );
    } else {
        Intent myIntent = new Intent( Commander2.this, LevelZero.class );
        startActivity( myIntent );
    }
}
}

Here is the XML file as well.

<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:onClick="accessCodeEntered"
        android:text="OK" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/button1"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="19dp"
        android:ems="10"
        android:inputType="textPassword" >

        <requestFocus />
    </EditText>

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/editText1"
        android:layout_alignLeft="@+id/editText1"
        android:text="Enter Access Code, or leave blank for Level 0"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</RelativeLayout>

My code just exits as soon as I enter a password and press the OK button, no matter what the output. I have commented out the startActivity( myIntent ) lines and the code finishes without crashing. Does anyone know what I’m doing wrong?

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="my.eti"
  android:versionCode="1"
  android:versionName="1.0">
<uses-sdk android:minSdkVersion="10" />
<application android:icon="@drawable/ic_launcher" android:label="@string/app_name">
    <activity android:name=".Commander2"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
     <activity android:name=".LevelOne"
              android:label="@string/app_name">
        <intent-filter>                
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".LevelZero"
              android:label="@string/app_name">
        <intent-filter>                
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
</manifest>
  • 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-05T05:21:53+00:00Added an answer on June 5, 2026 at 5:21 am

    EDIT : i am updating my answer

    so finally i got where you were going wrong

    • check your if condition
    • in accessCodeEntered() method
    • of Commander2.java Activity

     if(loginPassword.toString().equals(LEVEL_ONE_ACCESS_CODE)){}
    

    here you are not getting the value of password and try to use it
    so i added “getText()” method and its working fine like this


    if(loginPassword.getText().toString().equals(LEVEL_ONE_ACCESS_CODE)){}
    

    Commander2.java


    package my.eti;
    
    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.EditText;
    
    public class Commander2 extends Activity implements OnClickListener {
        /** Called when the activity is first created. */
    
        private static final String TAG = "AccessCodeEntry";
        private static final String LEVEL_ONE_ACCESS_CODE = "derp";
    
        private Button btnOK;
        private EditText passTxt;
    
        private String strPass;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.accesscodeentry);
    
            passTxt = (EditText) findViewById(R.id.editText1);
    
            btnOK =(Button) findViewById(R.id.button1);
            btnOK.setOnClickListener(this);
        }
    
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
    
            if(v==btnOK){
    
                /*... here is the problem we havent added getText() to get value from EditText...*/
            if(loginPassword.getText().toString().equals(LEVEL_ONE_ACCESS_CODE)){
                Intent myIntent = new Intent( Commander2.this, LevelOne.class );
                Toast.makeText(getBaseContext(), "if condition is true..", Toast.LENGTH_SHORT).show();
                startActivity( myIntent );
            }
            else{
                Intent myIntent = new Intent( Commander2.this, LevelZero.class );
                Toast.makeText(getBaseContext(), "else condition is true..", Toast.LENGTH_SHORT).show();
    
                startActivity(myIntent);
            }
            }
    
        }
    }
    

    try to implement this code and where you going wrong.

    still you get any trouble share with me Thanks.

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

Sidebar

Related Questions

has anyone know how to put/move this email send code to the service?? here's
I know C# has the Random class and probably a few classes in LINQ
I know Matlab has a function called cylinder to create the points for a
This is a question that I know has been asked here and several other
I've got an app, that has 2 activity, the first one launch the second
I know there has to be a way: I need help getting any hot
I know C# has both value and reference types, but how can you do
I know this has been asked all over the web in various different scenarios,
I know this has been asked different ways several times, but I'm just not
I know this has been asked thousands of times but I just can't find

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.