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.

1
  • long live the android manifesto! Mar 7, 2012 at 8:39

8 Answers 8

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);
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>
0

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

1
  • Manifest now simply reads <activity android:name=".Verification" android:label="Verification"></activity> but still no luck. Thanks though.
    – TrueWheel
    Nov 7, 2011 at 23:37
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.

2
  • Thanks for the advice and link. I have tried getApplicationContext() but still nothing! Thanks for your suggestion.
    – TrueWheel
    Nov 7, 2011 at 23:38
  • 1
    Is there no output in logcat either? Nov 7, 2011 at 23:52
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);

    }
    });
1
  • Hi, thanks for your response. I made your changes but still nothing happens when I press the button. Thanks again.
    – TrueWheel
    Nov 7, 2011 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;

3
  • Manifest not simply reads <activity android:name=".Verification" android:label="Verification"></activity> but still no luck. Thanks though.
    – TrueWheel
    Nov 7, 2011 at 23:36
  • 1
    now try this maybe? Intent intent=new Intent(CSLearn_Python_AppActivity.this, Verification.class); startActivity(intent); Nov 7, 2011 at 23:47
  • also it looks like you have to implements OnClickListener Nov 7, 2011 at 23:48
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>
0

You include the other activity in Manifest file:

Intent intent =  new Intent(First.this, Second.class);intent.putExtra("userData",registeredUsersData);startActivity(intent);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.