0

I am trying to launch a new activity when a button is pressed but nothing happens and I get no errors. Here is my code:

Main activity

public class CSLearn_Python_AppActivity extends Activity {


String tag = "Events";

/** Called when the activity is first created. */


@Override
public void onCreate(Bundle savedInstanceState) {


    //get content from main.xml
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);



    Button login = (Button) findViewById(R.id.loginBtn);
    login.setOnClickListener(new OnClickListener(){
        public void onClick(View v){



//              Intent intent = new Intent("com.Main.Verification");   
//              startActivity(intent);

            Intent myIntent = new Intent(getBaseContext(), Verification.class);
            startActivity(myIntent);

        }
    });



 }

The new activity

    import android.app.Activity;
import android.os.Bundle;

public class Verification extends Activity{

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.verification);

}

}

Verification XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/linearLayout1" android:layout_width="match_parent" android:baselineAligned="true" android:layout_height="match_parent" android:layout_gravity="center" android:gravity="center" android:orientation="vertical">
    <TextView android:text="@string/Verification" android:id="@+id/Verrification" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
    <EditText android:layout_height="wrap_content" android:id="@+id/password" android:inputType="textPassword" android:layout_width="112dp">
        <requestFocus></requestFocus>
    </EditText>
    <Button android:text="@string/LoginBtn" android:id="@+id/loginBtn" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>

I added this to the android manifesto

<activity android:name=".Verification"
              android:label="Verification">
        <intent-filter>
            <action android:name="com.Main.VERIFICATION" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

If anyone can point me in the right direction it would be really appreciated.

XXX
  • 8,996
  • 7
  • 44
  • 53
TrueWheel
  • 997
  • 2
  • 20
  • 35

8 Answers8

5

Try the code below and register your activity in the AndroidManifest.xml file:

Intent myIntent = new Intent(CSLearn_Python_AppActivity.this, Verification.class);
startActivity(myIntent);
user
  • 86,916
  • 18
  • 197
  • 190
Prabu
  • 1,441
  • 15
  • 20
1

Is CSLearn_Python_AppActivity in the same package than Verification.

May be you can try in the Manifest with:

<activity android:name="yourpackage.Verification"
                  android:label="@string/verification" >
        </activity>
chemalarrea
  • 1,385
  • 13
  • 11
0

You include the other activity in Manifest file:

Intent intent =  new Intent(First.this, Second.class);intent.putExtra("userData",registeredUsersData);startActivity(intent);
Jaap
  • 81,064
  • 34
  • 182
  • 193
Farruh Habibullaev
  • 2,342
  • 1
  • 26
  • 33
0

The intent-filter in your Verification activity is not necessary.

Ben Weiss
  • 17,182
  • 6
  • 67
  • 87
0

I believe the problem lies in the getBaseContext(). Use getApplicationContext() instead (the activity's context is also an option but would cause a leak). I havent quite been able to wrap my head around the base context, but it seems to be some sort of proxy doing more or less nothing in its raw implementation.

A more through explanation of the different contexts is given here.

Community
  • 1
  • 1
Kristian Evensen
  • 1,315
  • 13
  • 14
0

I would try to change it like this:

    Button login = (Button) findViewById(R.id.loginBtn);
    login.setOnClickListener(new OnClickListener(){
    public void onClick(View v){
        Intent myIntent = new Intent(v.getContext(), Verification.class);
        startActivity(myIntent);

    }
    });
Martin Nuc
  • 5,604
  • 2
  • 42
  • 48
  • Hi, thanks for your response. I made your changes but still nothing happens when I press the button. Thanks again. – TrueWheel Nov 07 '11 at 23:34
0

try removing the intent filter, and everything in between, from your manifest

do you have all your imports? import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button;

0
Intent myIntent = new Intent(CSLearn_Python_AppActivity.this, Verification.class);
startActivity(myIntent);

In your Android manifest file, 

<activity android:name=".Verification" android:label="Verification"></activity>
CAMB
  • 51
  • 1