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,870
  • 7
  • 43
  • 53
TrueWheel
  • 987
  • 2
  • 19
  • 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,378
  • 18
  • 196
  • 190
Prabu
  • 1,431
  • 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
  • 77,147
  • 31
  • 174
  • 185
Farruh Habibullaev
  • 2,133
  • 1
  • 23
  • 32
0

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

keyboardsurfer
  • 15,932
  • 6
  • 62
  • 86
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,257
  • 11
  • 13
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,364
  • 2
  • 40
  • 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